在ubuntu 16.04上安装pip

时间:2018-04-13 12:56:29

标签: python python-3.x ubuntu pip

我正在为python3安装@Repository public class RepositoryImpl extends AppJdbcImpl implements Repository { private static final StudentMapper STUDENT_ROW_MAPPER = new StudentMapper(); private static final CourseMapper COURSE_ROW_MAPPER = new CourseMapper(); @Value("classpath:sql/sql1.sql") private Resource sql1; private String query1; @Value("classpath:sql/sql2.sql") private Resource sql2; private String query2; public RepositoryImpl() { } public RepositoryImpl(NamedParameterJdbcOperations jdbc) { super(jdbc); } @PostConstruct public void setUp() { query1 = loadSql(sql1); query2 = loadSql(sql2); } public Iterable<Course> findCoursesByStudentId(int studentId) throws DataAccessException { try { return jdbc().queryForObject(query1, ImmutableMap.of("studentId", studentId), COURSE_ROW_MAPPER); } catch (EmptyResultDataAccessException emptyResult) { return null; } catch (DataAccessException e) { // Need to create exception classes and throw specific exceptions throw e; } } public Iterable<Student> findStudentsByCourseId(int courseId) throws DataAccessException { try { return jdbc().query(query2, ImmutableMap.of("courseId", courseId), STUDENT_ROW_MAPPER); } catch (DataAccessException e) { // Need to create exception classes and throw specific exceptions throw e; } } private String loadSql(Resource resource) { try { return CharStreams.toString(new InputStreamReader(resource.getInputStream())); } catch (IOException e) { return null; } } 。我使用了以下命令:

@RunWith(MockitoJUnitRunner.class)
public class RepositoryImplTest {
@Mock
private NamedParameterJdbcOperations jdbc;

@Mock
private ResultSet resultSet;

@Mock
private StudentMapper studentMapper;

@Mock
private CourseMapper CourseMapper;

@InjectMocks
private RepositoryImpl repository;

private Student student1;
private Student student2;

private Course course1;
private Course course2;

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);

    course1 = new Course(1, "Karate");
    course2 = new Course(2, "Riding");
    course8 = new Course(8, "Swimming");
    List<Course> courseList = Arrays.asList(course1, course2, course8);

    student1 = new Student(1, "Chuck", "Norris", 27, new Arrays.asList(course1, course2));
    student2 = new Student(2, "Bruce", "Lee", 54, new Arrays.asList(course1, course8));
    List<Student> studentList = Arrays.asList(student1, student2);

    when(jdbc.queryForObject(Matchers.anyString(), anyMap(),
        isA(StudentMapper.class)))
        .thenAnswer(new Answer() {
            @Override
            public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
                Object[] args = invocationOnMock.getArguments();
                int queryParam = Integer.parseInt(args[0].toString());

                Iterable<Credentials> result = studentList.stream()
                .filter(d -> d.getId() == queryParam)
                .collect(Collectors.toList());

                return result;
            }
        });
}

@Test
public void findCoursesByStudentId() {
    Iterable<Course> result = repository.findCoursesByStudentId(1);
    assertNotNull(result);
}

enter image description here

但是在安装之后仍然说没有安装pip

enter image description here

我安装了sudo apt-get install python3-pip

3 个答案:

答案 0 :(得分:8)

python3-pip包安装Python 3的pip,名为pip3。简单pip是Python 2的pip,它由python-pip包安装。

答案 1 :(得分:5)

安装它的最佳方法是:

wget https://bootstrap.pypa.io/get-pip.py

cd ~/Downloads/(如果你的版本是英文版,法文版就是Téléchargements

然后,一旦下载,请尝试:

sudo python3 get-pip.py

答案 2 :(得分:-2)

easy_install -U pip:这解决了我在ubuntu 16.04上的问题