0

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.

math
  • 1,868
  • 4
  • 26
  • 60

2 Answers2

1

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.

Błażej Michalik
  • 4,474
  • 40
  • 55
  • thanks, that seems to work. But I don't get it. Isn't pyenv supposed to call the correct pip if the global version is set to python 3.5.3? I'm using Debian – math Jun 23 '17 at 15:52
  • @user8 I don't use pyenv so I can't tell, but my guess would be, that it is due to the `sudo`. If you use `sudo`, you are effectively using another user account, so the environment changes. – Błażej Michalik Jun 23 '17 at 15:53
  • for me pyenv chooses the correct pip but I always set the version of python local to a directory. Never use sudo or pip3 with my pyenv.. – cardamom Jun 23 '17 at 15:54
  • @user8 You could also try `sudo --preserve-env` or `sudo -E` just to see if that works. – Błażej Michalik Jun 23 '17 at 15:54
  • @cardamom There isn't really any other way (well, maybe apart from `su`, but that's the same thing tho) if you wan't to tell pip to install something system-wide. You need root permissions for that. – Błażej Michalik Jun 23 '17 at 15:56
  • I've tested this using the `---preserve-env`. Howerver, I get the same error message as in my question, i.e. running ` sudo -E pip install numpy` – math Jun 23 '17 at 15:57
  • @user8 Weird. Anyway, using `sudo` with `pip` is always a mixed-bag for me, as the only thing that makes it use the correct python version is the shebang in `/usr/bin/pip` or `/usr/bin/pip3`. Even weirder, both of those use python3. I have no idea why. – Błażej Michalik Jun 23 '17 at 16:01
  • @BłażejMichalik I'm not an expert but if it annoys you would suggest just running `pyenv local 3.5.3` in each directory where you want to use Python stuff, it puts a hidden file there, might be less dependent of broader system settings. – cardamom Jun 23 '17 at 16:02
  • @cardamom Yeah, sure, but the OP indicated an intention of system-wide usage, so usage of user-space pip is a no-go. – Błażej Michalik Jun 23 '17 at 16:04
1

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.
wjv
  • 2,288
  • 1
  • 18
  • 21