Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why pip3 install in python2 sitepackages

First I use

Python 3.6.5
Python 2.7.14
and mac.

In my case, I just download module like numpy(for example, and other's same) when i use pip3 it said like.. enter image description here

and pip is same.

but when I use it, in python3enter image description here

In python2, It working well... enter image description here

How can I fix it?

like image 480
최연석 Avatar asked Jun 27 '18 05:06

최연석


People also ask

Does pip install for both Python 2 and 3?

In this article, learn how to install pip on Ubuntu 18.04. Note: If you are using Python in a virtual environment created with pyvenv or virtualenv, then pip is available regardless of the version of Python in use. This also applies to Python 2.7. 9 or newer (Python series 2) and Python 3.4 or later (Python series 3).

Can you use pip3 for python2?

It seems that pip3 refers to Python-2.7's pip module or any other version of Python-3 that you have installed on your machine. However, you can install packages directly using the intended Python version. You'd need to just use -m option.

Is pip for python2?

pip installationTo use pip, first install a custom version of Python 2. pip is then installed with it. You can then use the pip command to create a virtualenv and install modules.

Does Python 3.10 support pip?

Compatibility. The current version of pip works on: Windows, Linux and MacOS. CPython 3.7, 3.8, 3.9, 3.10 and latest PyPy3.


2 Answers

It seems that pip3 refers to Python-2.7's pip module or any other version of Python-3 that you have installed on your machine. However, you can install packages directly using the intended Python version. You'd need to just use -m option.

python3.6 -m pip install numpy

Another option is to changing the source path that pip3 refers to. You can do this by finding the path of Python-3.6's pip and just bind it to pip3 alias.

like image 91
Mazdak Avatar answered Sep 30 '22 19:09

Mazdak


Find the absolute path of the python3 interpreter with a command like this:

$ which python3
/Library/Frameworks/Python.framework/Versions/3.6/bin/python

Your path may be something different, of course. Copy that line to your clipboard.

Edit the pip3 script, which was installed using incorrect interpreter. Something like this:

vi $(which pip3)

You might need to use sudo here, but try it first without. The first line will be something like:

#!/Library/Frameworks/Python.framework/Versions/2.7/bin/python

Change it to the path found in the previous step, e.g.

#!/Library/Frameworks/Python.framework/Versions/3.6/bin/python

Save the pip3 file and exit. This should be sufficient to associate pip3 with the correct environment. Check and verify the result with pip3 --version. Now pip3 install numpy should work as expected.

like image 37
wim Avatar answered Sep 30 '22 17:09

wim