ImportError using pip install on Mac OSX - python

I installed a module called mrjob using sudo pip install mrjob. When I start python and try to import it, I get ImportError: No module named mrjob.
Using iname, I find out that mrjob is installed in /lib/python2.7/site-packages/, while all my Python modules are in /usr/local/lib/python2.7/site-packages. So I add the new folder to my PATH with export PATH=/lib/python2.7/site-packages:$PATH.
But even after I do that, I still get ImportError. If I cd to /lib/python2.7/site-packages/ and start python from there, it imports the module correctly.
I also tried to uninstall the module:
> sudo pip uninstall mrjob
Password:
Cannot uninstall requirement mrjob, not installed
If I do:
>>> import site; site.getsitepackages()
['/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages', '/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/site-python', '/Library/Python/2.7/site-packages']
The folder /lib/python2.7/site-packages/ isn't there.
== UPDATE ==
The following command worked
pip install --install-option="--prefix=/usr/local" mrjob
I can now import mrjob correctly. But I still don't understand what is going on.

I got this problem too. Cause python use the system pre-install python at
/Libarary/Python
But this python without pip. while I install pip, it will install at
/usr/local/Libarary/Python
My solution is install pip for the system by this:
sudo easy_install -U pip

Related

ModuleNotFoundError: No module named 'kmodes'

I have tried installing it using pip install kmodes and it says that "Requirement is satisfied" but am not being able to import the library even after that.
The list of libraries doesn't have kmodes even after installing. Attaching screenshot for reference. What is happening here?
from kmodes.kprototypes import KPrototypes
ModuleNotFoundError: No module named 'kmodes'
Maybe your PIP is installing to the wrong version of python and the code you are running is being interreted by a later version
Try copying your python executable path and running this
C:\Users\username\AppData\Local\Programs\Python\Python39\python.exe -m pip install kmodes
Another reason is that kmodes did not install properly the first time
Try running this as an administrator
pip uninstall kmodes && pip install kmodes

pip install modules to 2.7.10 rather than 2.7.13 causing default python2.7.13 can't import those modules on MAC terminal window

As u can see from the question, I run sudo pip install pymysql successfully.
But it seems to be installed in 2.7.10 rather 2.7.13. I find it when tried to get python version before as well as after using sudo -i.
Then I listed all modules install using help('modules') and suprisingly to find 2.7.10 has but 2.7.13 don't have pymsql .
It failed to run pip2.7.13 install pymysql .Only pip2.7 install pymysql works .
I wonder how to config pip to install modules to 2.7.x or change my default python version from 2.7.13 to 2.7.10 ?
You may try to install python packages without root permission:
pip install --user pymysql
The option --user allow pip to install packages in your \home directory instead. That means it doesn't need any special privileges.
I finally find the cause:
My computer has an software named MAMP which has python2.7.13 env itself and pushes the python to the global.But pip will install modules into the computer's own python2.7.10, which causes now global python2.7.13 cannot import the installed modules.
Solution:
1,Find out the location of modules installed by pip and copy them to the
python directory in mamp. Commands as below:
cp -r /Library/Python/2.7/site-packages/pymysql/* /Applications/MAMP/Library/lib/python2.7/pymysql/
2, Then I can feely import modules installed by pip in global python now ~

Getting ImportError: No module named 'Crypto' after installation

I am getting ImportError: No module named 'Crypto' error when trying to run. I have installed pycrypto using pip install pycrypto and updated it also. Everything I have tried to far has been unsuccessful.
Tried:
reinstalling pycrypto,
updating both python and pycrypto
Any suggestions?
The error messages says, it does not able to find the module so please try to run below command,
#pip list -- # what does it show to you, if it would have installed successfully it will show you up there.
if "pip install pycrypto" doesn't work so try to download the source tar ball and try to install it from prompt.
pip download pycrypto
it will download tar.gz file.. so you can install using with pip install --no-index --find-links /path/to/some/dir/ pycrypto
for python3.5 version
python3.5 -m pip install pycrypto
this will install in python3.5 environment and after that you can able to import pycrypto module
Is python defined properly on your machine?
Make sure PATH environment variable has python's installation folder in it

Python ImportError: no module named os

Trying to upgrade matplotlib as in this post, I ran
export PYTHONHOME=/usr/lib/python2.7/
sudo easy_install -U distribute
sudo pip install --upgrade matplotlib
Now whenever I try to run python I get ImportError: no module named os. What happened? Please help me. I'm on OS X 10.9.5.
The issue was changing PYTHONHOME, which could not find any modules because I have python running out of a user directory /Users/alavin89/Library/Python/2.7/lib/python/site-packages. Check the python path by running echo $PYTHONPATH.
The fix:
unset PYTHONHOME
sudo pip uninstall matplotlib
pip uninstall matplotlib
pip install --user matplotlib
Note: running uninstall again w/o sudo is to double-check it worked properly.
Use Anaconda.
https://store.continuum.io/cshop/anaconda/
It has every Python package you could possibly think of - including matplotlib - it updates them all at once as well.

pip setup and setting PYTHONPATH

I'm not experienced in Python, and I need the requests module.
I've tried installing it using pip install requests
The installation went successfully, but when I try to import the module, I get an error like "no module named requests".
Should I add the install location to PYTHONPATH? If yes, how can I find the location where pip installed the files? I don't know about virtualenv, and I am using Ubuntu.
You should install pip for python3 first
How to install pip with Python 3?
then with the pip-3.X install the required module.

Categories