简体   繁体   中英

pip3 install not working properly and cannot link to python3

I am using a Mac and have both python 2 and 3 installed. However when I try to run a python 3 script and it says module pandas not found, Then I tried the following commands:

pip3 install pandas  AND 
python3 -m pip install pandas

However the error remains the same. I tried to look at installed location of pip3 and python3 and something is not right. Below is the image of which -a python and pip. How do I fix it?

The python and pip installed location Image

1个

If you have both python versions and want to have python3 as default version, you should set the default path to python3 and pip3.

# for zsh
$ echo "alias python=/usr/local/bin/python3.7" >> ~/.zshrc
# or for bash
$ echo "alias python=/usr/local/bin/python3.7" >> ~/.bashrc

# for zsh
$ echo "alias pip=/usr/local/bin/pip3" >> ~/.zshrc 
# or for bash
$ echo "alias pip=/usr/local/bin/pip3" >> ~/.bashrc

That will run your default operations on python3, assuming that the installed version is 3.7.

Secondly, it will be better to use virtualenv in case of multiple python environments

So it seems pip3 was installed in 2 different directories. /usr/local/bin/pip3 and /usr/bin/pip3 and python3 was installed in /usr/bin/

I used "rm /usr/locak/bin/pip3" to remove pip3 from default location, Now both pip3 and python3 are in /usr/bin/ and now I can install packages using "pip3 install --user pandas" for python3 and "pip install pandas" for python 2.

Thank you @mapto for your idea to check installation directories.

please look into virtualenv (and optionally virtualenvwrapper). those will isolate your in-built Python and Installed Python versions and modules. so you can avoid the overlaps / conflicts.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM