math
math

Reputation: 2022

pyenv failing to install package for python 3.5.3

I have multiple version of python on my machine that's why I've installed pyenv to manage them. According to pyenv I have

ola@station:~$ pyenv versions
* system (set by /home/ola/.pyenv/version)
  3.4.6
  3.5.3
  3.6.1

I set the global (system default) to 3.5.3 as you can see

ola@station:~$ pyenv global
3.5.3

I would like to install numpy for python 3.5 as it is a missing module there. If I correctly understood how pyenv works, when I'm running sudo pip install numpy pyenv figure out that the global version to use is 3.5.3 and install numpy for that, correct?

However, I get the following issue:

ola@station:~$ sudo pip install numpy
Traceback (most recent call last):
  File "/usr/local/bin/pip", line 6, in <module>
    from pkg_resources import load_entry_point
  File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2991, in <module>
    @_call_aside
  File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2977, in _call_aside
    f(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 3004, in _initialize_master_working_set
    working_set = WorkingSet._build_master()
  File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 664, in _build_master
    return cls._build_from_requirements(__requires__)
  File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 677, in _build_from_requirements
    dists = ws.resolve(reqs, Environment())
  File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 856, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'pip==8.1.2' distribution was not found and is required by the application

How can I resolve this?

NOTE Running sudo pip3 install numpy doesn't help since it tells me

ola@station:~$ sudo pip3 install numpy
Requirement already satisfied: numpy in /usr/local/lib/python2.7/dist-packages

But there doesn't exist a numpy for python 3.5.3 on my machine. As far as I understood pip3 version and python version are different things.

Upvotes: 0

Views: 2826

Answers (2)

wjv
wjv

Reputation: 2618

This is an old question, but for anyone else stumbling across it:

Use pyenv which to determine which script/executable will be executed. For instance, if 3.5.3 is your currently currently active version of Python, you should see the following:

ola@station:~$ pyenv which pip3
/home/ola/.pyenv/versions/3.5.3/bin/pip3

At this point you can just do:

pip3 install numpy

No su or sudo required, since the entire pyenv installation is in your home directory under ~ola/.pyenv/.

In all the examples you show in your question, it appears that 3.5.3 had not been correctly activated, since the system-wide version of Python 2.7 under /usr/local was involved. So:

  • Use pyenv version to check the currently active version.
  • Use pyenv which <script> to see exactly which script will be executed.

Upvotes: 1

Błażej Michalik
Błażej Michalik

Reputation: 5085

You could try:

sudo python3 -m pip install numpy

If that doesn't work, you could try deleting numpy from python2. From what I remember, Ubuntu has some weird quirks when it comes to pip, so it depends on your OS/distribution too.

Upvotes: 1

Related Questions