15

I'm having problems with python3. For some reason that I cannot figure out, the modules available in python3 are not the same as the ones installed via pip3.

Running pip3 list in a Terminal returns:

DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
nltk (3.2.2)
numpy (1.12.0)
pandas (0.19.2)
pip (9.0.1)
python-dateutil (2.6.0)
pytz (2016.10)
setuptools (25.2.0)
six (1.10.0)
wheel (0.29.0)

Running this script to see what modules python3 has available returns:

 ['cycler==0.10.0', 'matplotlib==1.5.3', 'nltk==3.2.1', 'numpy==1.11.2', 'pip==9.0.1', 'pyparsing==2.1.10', 'python-dateutil==2.6.0', 'pytz==2016.7', 'setuptools==18.2', 'six==1.10.0']

These two are not the same and I can't tell why. nltk, for example, has an older version. pandas is missing.

I've installed python via homebrew and I'm running scripts via Textmate2. However, I have the same problem when I run code in terminal, via python3. Both pip3 and python3 are installed in /usr/local/bin/:

$ which python3 pip3
/usr/local/bin/python3
/usr/local/bin/pip3

And that's also the version python3 is using:

>>> import sys, os
>>> os.path.dirname(sys.executable)
'/usr/local/bin'

If someone could help me figure out why this is the case, and how I can fix it, I would very much appreciate the help.

Community
  • 1
  • 1
altabq
  • 1,322
  • 1
  • 20
  • 33

2 Answers2

12

Look at the first line of the pip3 script.

The first line (starting with #! should point to the same executable as the symbolic link for python 3:

> head -n 1 /usr/local/bin/pip
#!/usr/local/bin/python3.6

> ls -ld /usr/local/bin/python3
lrwxr-xr-x  1 root  wheel  9 Dec 25 22:37 /usr/local/bin/python3@ -> python3.6

If this is not the case, deinstall pip and install it again with the correct Python version.

EDIT:

If you really want to make sure that you're using the the right Python with pip, then call it as a module like this:

python3.7 -m pip list

If you get the error No module named pip, then pip is not installed for this version of python.

Roland Smith
  • 42,427
  • 3
  • 64
  • 94
  • You're right, pip pointed to an old install of python3 I didn't know I had. I [removed everything](http://superuser.com/a/276843/308345) and did a clean install via homebrew. Everything is working again now. Thanks! – altabq Feb 20 '17 at 12:50
  • had to change the path to ls -ld /usr/bin/python3 – Winnipass Jan 18 '19 at 20:49
  • > head -n 1 /usr/local/bin/pip #!/usr/local/opt/python/bin/python3.6 but > ls -ld /usr/local/bin/python3 ls: /usr/local/bin/python3: No such file or directory what should I do? – Michael Apr 27 '21 at 07:10
  • @Michael You could for example add `usr/local/opt/python/bin` to your path, or create a `python3` symbolic link in `/usr/local/bin/` pointing to `/usr/local/opt/python/bin/python3.6`. – Roland Smith Apr 27 '21 at 18:48
1

I ran to this problem in Windows. first of all I uninstall the package using cmd command pip3 uninstall moduleName. Then based on python documentation I run command python -m pip install moduleName and my problem solved!

Here is the documentation: Installing Python Modules

Samikohtor
  • 11
  • 1