3

For some reason, pip3 does not install packages to the proper dist-packages directory, at least not the directory I expect.

I am trying to install the package cleverwrap currently, but this happens for all packages installed with pip3 as far as I can tell.

I am running this command:

sudo pip3 install cleverwrap

This command installs to /usr/local/lib/python2.7/dist-packages/

Shouldn't it install to /usr/local/lib/python3.4/dist-packages/ ?

crawforc3@raspberrypi:~$ python --version
Python 2.7.9

crawforc3@raspberrypi:~$ python3 --version
Python 3.4.2

crawforc3@raspberrypi:~$ which pip
/usr/local/bin/pip

crawforc3@raspberrypi:~$ which pip3
/usr/local/bin/pip3

crawforc3@raspberrypi:~$ python3 -m pip install cleverwrap
/usr/bin/python3: No module named pip

crawforc3@raspberrypi:~$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games

Output from pip3 show cleverwrap

crawforc3@raspberrypi:~$ pip3 show cleverwrap
Name: cleverwrap
Version: 0.2.3.2
Summary: A wrapper for the official cleverbot.com API
Home-page: https://github.com/edwardslabs/cleverwrap.py
Author: Andrew Edwards
Author-email: andrewthomasedwards@gmail.com
License: MIT
Location: /usr/local/lib/python2.7/dist-packages
Requires: requests

@Hydraxan14 suggested this answer:

https://stackoverflow.com/questions/31407208/pip3-4-v-refers-to-python2-7-installation/35182033#35182033

I changed where pip looks for python3. This resulted in a version conflict. Something was looking for a different version of pip than was installed.

Output from pip3 -V

crawforc3@raspberrypi:/usr/local/bin$ pip3 -V
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/pkg_resources.py", line 449, in _build_master
    ws.require(__requires__)
  File "/usr/lib/python3/dist-packages/pkg_resources.py", line 745, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/usr/lib/python3/dist-packages/pkg_resources.py", line 644, in resolve
    raise VersionConflict(dist, req)
pkg_resources.VersionConflict: (pip 1.5.6 (/usr/lib/python3/dist-packages), Requirement.parse('pip==9.0.1'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/pip3", line 5, in <module>
    from pkg_resources import load_entry_point
  File "/usr/lib/python3/dist-packages/pkg_resources.py", line 2876, in <module>
    working_set = WorkingSet._build_master()
  File "/usr/lib/python3/dist-packages/pkg_resources.py", line 451, in _build_master
    return cls._build_from_requirements(__requires__)
  File "/usr/lib/python3/dist-packages/pkg_resources.py", line 464, in _build_from_requirements
    dists = ws.resolve(reqs, Environment())
  File "/usr/lib/python3/dist-packages/pkg_resources.py", line 639, in resolve
    raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: pip==9.0.1

Updating pip3 with this command solved the version conflict and everything works now.

sudo python3 -m pip install pip --upgrade
  • What directory do you expect it to install to?What directory does it install to? Given that you have repeatedly installed/uninstalled you may be best off startingf with a fresh install. What package(s) are you trying to install? – Steve Robillard Mar 2 '17 at 20:19
  • @SteveRobillard pip, pip2, and pip3 all install to /usr/local/lib/python2.7/dist-packages instead of /usr/local/lib/python3.4/dist-packages. – Chris Mar 2 '17 at 20:45
  • First, you have only answered one of the many questions I asked. Second, the answers belong in your question not the comments. What pip command are you using to install? – Steve Robillard Mar 2 '17 at 20:47
  • @SteveRobillard You asked three questions, I answered two directly and the other is in the question itself. You're not being helpful so why even reply? – Chris Mar 2 '17 at 22:55
  • 1
    I think the root cause is your admitted tinkering. I just ran the install on one of my Pi's and got Location: /usr/local/lib/python3.4/dist-packages from pip show cleverwrap. As I mentioned it may be best to reimage your SD card and start fresh. – Steve Robillard Mar 3 '17 at 0:23
1

pip3 is being run with python2.7

I found this stack overflow answer which might pertain to this situation.


Summary

Basically, /usr/local/pip3 has the #!/usr/bin/python shebang as its first line, which causes it to be run by the python2.7 interpreter, and not the python3 interpreter.

This might be causing your issue.

The linked answer mentions changing pip3's shebang to #!/usr/bin/python3 to force it to be run with the python3 interpreter.


I hope this helps!

  • Running cat /usr/bin/pip3 shows #!/usr/bin/python3 so this is not likely the cause. – Steve Robillard Mar 3 '17 at 0:26
  • @Hydraxan14 This answer causes a version conflict. However, running python3 -m pip install pip --upgrade fixed that. If you want to add this to the answer I qill accept it. – Chris Mar 3 '17 at 0:46
  • @Chris That sounds like something quite different than what I suggested. Perhaps it would be best if you posted that as a separate answer. – Hydraxan14 Mar 23 '17 at 20:34
0

@Hydraxan14's answer got me going in the right direction.

pip3 is being run with python2.7

I found this stack overflow answer which might pertain to this situation.


Summary

Basically, /usr/local/pip3 has the #!/usr/bin/python shebang as its first line, which causes it to be run by the python2.7 interpreter, and not the python3 interpreter.

This might be causing your issue.

The linked answer mentions changing pip3's shebang to #!/usr/bin/python3 to force it to be run with the python3 interpreter.


After making the change suggested in the link that @Hydraxan14 suggested, I was left with a pip3 version conflict which was easily fixed by updating pip3 by running:

python3 -m pip install pip --upgrade

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.