How to use pip with multiple instances of python

2019-08-02 03:50发布

问题:

I recently installed python3 only to realize that mysql-python as well as many other modules were not well supported with it yet. So I changed the path in my bashrc file to point to an installation of python 2.7. The problem is that when I installed python 3 I also installed distribute and pip along with it. I removed the pip and distribute files from the python3 bin directory and installed setuptools and pip using python 2.7 however now when I use the pip command to install django and mysql-python, I get a bash error python331/bin/pip No such file or directory. It's still looking for pip in the python3 install. How can I remedy this?

Thanks

回答1:

...I get a bash error python331/bin/pip No such file or directory. It's still looking for pip in the python3 install. How can I remedy this?

bash, by default, hashes the locations of commands to avoid searching $PATH each time, so if, when you execute...

$ type pip

...you get something like...

pip is hashed (python331/bin/pip)

...you just need to clear the hash table for bash with...

$ hash -r

...then it'll pick up the version in Python 2.7 the next time you try to run pip.



回答2:

Fixed it.

Renamed the directory of where the python3 was installed, bash automatically looks for the next available python install python 2.7



标签: python bash pip