0

Ubuntu 18.04 used by me (a noob) who has pip installed packages all over the place until I learned the benefit of virtual environments. My .bash rc file contains:

  #setup for python
    export PYTHONPATH=/home/stefan/.local/
    export PYTHONPATH=/usr/local${PYTHONPATH:+:${PYTHONPATH}}
    export PYTHONPATH=/home/stefan/caffe/python:$PYTHONPATH
    LD_LIBRARY_PATH=/usr/local/lib${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

Anyway because I kept forgetting which virtual environments had which packages, I decided to use pip install --user like so:

pip install plumbum --user

which gave

~/.local/lib/python3.6/site-packages$ ls
plumbum  plumbum-1.6.7.dist-info

meanwhile

~/.local/lib/python2.7/site-packages$ ls
clonevirtualenv.py       stevedore
clonevirtualenv.pyc      stevedore-1.30.1.dist-info
imageio                  virtualenv-16.4.3.dist-info
imageio-2.5.0.dist-info  virtualenv_clone-0.5.1.dist-info
pbr                      virtualenv.py
pbr-5.1.3.dist-info      virtualenv.pyc
pip                      virtualenv_support
pip-19.0.3.dist-info     virtualenvwrapper
six-1.12.0.dist-info     virtualenvwrapper-4.8.4.dist-info
six.py                   virtualenvwrapper-4.8.4-nspkg.pth
six.pyc

Needless to say, I cannot use plumbum from a python2 prompt. I only use pip install so I To make matters more confusing I have a virtual env named pyCV3 which has

~/Envs/pyCV3/lib/python2.7/site-packages$ ls
backports
backports.functools_lru_cache-1.5.dist-info
backports.shutil_get_terminal_size-1.0.0.dist-info
cloudpickle
cloudpickle-0.8.1.dist-info
concurrent
cv2.so
cycler-0.10.0.dist-info
cycler.py
cycler.pyc
dask
dask-1.1.4.dist-info
dateutil
decorator-4.4.0.dist-info
decorator.py
decorator.pyc
easy_install.py
easy_install.pyc
enum
enum34-1.1.6.dist-info
futures-3.2.0.dist-info
imageio
imageio-2.5.0.dist-info
IPython
ipython-5.8.0.dist-info
ipython_genutils
ipython_genutils-0.2.0.dist-info
kiwisolver-1.0.1.dist-info
kiwisolver.so
matplotlib
matplotlib-2.2.4.dist-info
matplotlib-2.2.4-py2.7-nspkg.pth
mpl_toolkits
networkx
networkx-2.2.dist-info
numpy
numpy-1.16.2.dist-info
pathlib2
pathlib2-2.3.3.dist-info
pexpect
pexpect-4.6.0.dist-info
pickleshare-0.7.5.dist-info
pickleshare.py
pickleshare.pyc
PIL
Pillow-5.4.1.dist-info
pip
pip-19.0.3.dist-info
pkg_resources
pkg_resources-0.0.0.dist-info
_posixsubprocess32.so
prompt_toolkit
prompt_toolkit-1.0.15.dist-info
ptyprocess
ptyprocess-0.6.0.dist-info
pygments
Pygments-2.3.1.dist-info
pylab.py
pylab.pyc
pyparsing-2.3.1.dist-info
pyparsing.py
pyparsing.pyc
python_dateutil-2.8.0.dist-info
pytz
pytz-2018.9.dist-info
PyWavelets-1.0.2.dist-info
pywt
scandir-1.10.0.dist-info
scandir.py
scandir.pyc
_scandir.so
scikit_image-0.14.2.dist-info
scikit_learn-0.20.3.dist-info
scipy
scipy-1.2.1.dist-info
setuptools
setuptools-40.8.0.dist-info
shutil_backports
simplegeneric-0.8.1.dist-info
simplegeneric.py
simplegeneric.pyc
six-1.12.0.dist-info
six.py
six.pyc
skimage
sklearn
subprocess32-3.5.3.dist-info
subprocess32.py
subprocess32.pyc
tlz
toolz
toolz-0.9.0.dist-info
traitlets
traitlets-4.3.2.dist-info
wcwidth
wcwidth-0.1.7.dist-info
wheel
wheel-0.33.1.dist-info

Early on I also did a 'sudo pip install' so my system python folders look like this

~/.local/lib/python2.7/site-packages$ ls
clonevirtualenv.py       stevedore
clonevirtualenv.pyc      stevedore-1.30.1.dist-info
imageio                  virtualenv-16.4.3.dist-info
imageio-2.5.0.dist-info  virtualenv_clone-0.5.1.dist-info
pbr                      virtualenv.py
pbr-5.1.3.dist-info      virtualenv.pyc
pip                      virtualenv_support
pip-19.0.3.dist-info     virtualenvwrapper
six-1.12.0.dist-info     virtualenvwrapper-4.8.4.dist-info
six.py                   virtualenvwrapper-4.8.4-nspkg.pth
six.pyc

and

/.local/lib/python3.6/site-packages$ ls
plumbum  plumbum-1.6.7.dist-info

So I dont know why pip install decided to put plumbum into 3.6 instead of 2.7. Can someone enlighten me? (And perhaps give me a hint on how to clean up my mess).

I suspect it has something to do with the fact that my linux always uses pip3

~/.local/lib/python3.6/site-packages$ pip3 --version
pip 19.0.3 from /usr/local/lib/python3.6/dist-packages/pip (python 3.6)

~/.local/lib/python3.6/site-packages$ pip --version
pip 19.0.3 from /usr/local/lib/python3.6/dist-packages/pip (python 3.6)


~/.local/lib/python2.7/site-packages$ pip --version
pip 19.0.3 from /usr/local/lib/python3.6/dist-packages/pip (python 3.6)

~/.local/lib/python2.7/site-packages$ pip3 --version
pip 19.0.3 from /usr/local/lib/python3.6/dist-packages/pip (python 3.6)

I know there is a pip2 in my /usr/bin but linux does not like it

/usr/bin$ pip2 --version
Traceback (most recent call last):
  File "/usr/bin/pip2", line 9, in <module>
    from pip import main
ImportError: cannot import name main
aquagremlin
  • 3,515
  • 2
  • 29
  • 51

3 Answers3

4

In general you can call your Python interpreter with ./your/path/python -m pip install plumbum --user, to use the right pip.

Querenker
  • 2,242
  • 1
  • 18
  • 29
  • pip --version pip 19.0.3 from /usr/local/lib/python3.6/dist-packages/pip (python 3.6) stefan@4930:~/Envs/pyCV3/bin$ pip2 install plumbum --user Traceback (most recent call last): File "/usr/bin/pip2", line 9, in from pip import main ImportError: cannot import name main – aquagremlin Apr 01 '19 at 18:55
  • python2.7 -m pip install plumbum --user – aquagremlin Apr 01 '19 at 18:59
  • put plumbum into ~/.local/lib/python2.7/site-packages – aquagremlin Apr 01 '19 at 19:00
  • Try `~/Envs/pyCV3/bin/python -m pip install plumbum --user` – Querenker Apr 01 '19 at 19:01
  • well, my machine thinks 'python' refers to python2.7 – aquagremlin Apr 01 '19 at 19:04
  • ~/.local/lib/python2.7/site-packages$ python pip --version pip 19.0.3 from /home/stefan/.local/lib/python2.7/site-packages/pip (python 2.7) ~/.local/lib/python2.7/site-packages$ pip --version pip 19.0.3 from /usr/local/lib/python3.6/dist-packages/pip (python 3.6) – aquagremlin Apr 01 '19 at 19:04
  • as you can see from that poorly formatted comment above 'python pip' returns the python2 library but plain old 'pip' sends things to the python3 library – aquagremlin Apr 01 '19 at 19:05
  • I marked querenker's answer but I wish I could split the vote since you all have been kind and helpful – aquagremlin Apr 01 '19 at 19:06
  • I also have pip3 installed. How do I tell my machine that 'pip' refers to pip2 and how can I fix pip2 because as you saw, 'pip2' gives an error. – aquagremlin Apr 01 '19 at 19:08
  • In order to change your default pip there is an helpful question here on SO: https://stackoverflow.com/questions/42871090/change-default-ubuntu-pip-to-pip2-7 – Querenker Apr 01 '19 at 19:10
  • pip2 -V Traceback (most recent call last): File "/usr/bin/pip2", line 9, in from pip import main ImportError: cannot import name main – aquagremlin Apr 01 '19 at 19:14
  • how could i fix it? – aquagremlin Apr 01 '19 at 19:15
  • Have you tried to call pip from your python interpreter with the `-m pip' option? – Querenker Apr 01 '19 at 19:15
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/191045/discussion-between-aquagremlin-and-querenker). – aquagremlin Apr 01 '19 at 19:18
2

The reason why pip installed to your python3.6 library is because it is a default library for pip installation on your machine.

pip --version will return the location where pip is going to install your packages. If you want to install the package for python2.7, run pip2 install plumbum --user

I would also recommend to run pip2 --version beforehand.

EDIT:

I suggest you also look at this answer, to make sure you understand the differences between pip, pip3, python, python2, python3

Andrey Mikus
  • 71
  • 1
  • 3
1

Try to write on terminal 'python2.7 -m pip install ' if it fails install pip with a get-pip.py file, and try again, if it does not work, let me know