[PYTHON] If you should have pip installed but get an Import error

environment

MacOSX 10.12.2 pyenv 20160629

Method

If you get a ʻImport Error when trying to import a pip installed module, you have to make sure that $ PYTHONPATH` is set correctly.

The installation destination of the module installed by pip is / usr / local / lib / python2.7 / site-packages /, while the path when using pyenv is / Users / Hoge /. It is pyenv / shims / python / site-packages / . No wonder this doesn't load modules installed with pip.

Python basically searches for the path inside the environment variable $ PYTHONPATH. Therefore, by adding the installation path set by this pip to $ PYTHONPATH, it will be loaded normally.

$ export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages/

The rest is solved by adding the above script to .bashrc and .zshrc.

Recommended Posts

If you should have pip installed but get an Import error
For those who should have installed janome properly with Python but get an error
Solution if the module is installed in Python but you get an error in Jupyter notebook
Workaround if you get an error when trying to install PySide with pip
What to do if you get an Import Error when importing matplotlib with Jupyter
What to do if you get an Undefined error when trying to use pip with pyenv
I get an error with import pandas.
If you can't import even though it is already installed by pip
What to do if you get an error when trying to load mnist
What to do if you get an error when installing Dlib (Ubuntu)
What to do if you should have set an ssh key but are prompted for a password
Install openstack client from pip so you don't get an error on CentOS7
What to do if you get an error when installing python with pyenv
If you get a long error when tabbing an interactive shell with Anaconda
What to do if you get an "unknown service" error from your gRPC server
I get an Import Error in Python Beautiful Soup
If you get hooked on pip install dlib on OSX
What to do if you get an error when importing matplotlib in Python (Mac)
When you get an error in python scraping (requests)
What to do if you get Swagger-codegen in python and Import Error: No module named
What to do if you get an error when running "certbot renew" in CakePHP environment
Solution if you get 0xxx ascii coding error in superset
I have libncurses but get angry with pip install readline
EC2 / Amazon Linux2: What to do if you get an "unable to execute'gcc': No such file or directory" error with pip install
What to do if you get an error saying c compiler cannot create executables in configure
If you get Error: That port is already in use. In Django
I get an error when trying to install maec 4.0.1.0 with pip
What to do if you get a UnicodeDecodeError with pip install
Read this if you get SSL related errors with pip install! !! !!
What to do if you get an error like'Qstring' has already been set to version 1 using mne python
What to do if you have installed PyCharm but shortcut keys such as `control + e` do not work
Uninstall everything you installed with pip
The module that should have been installed with pip does not run
What to do if you get Could not fetch URL 443 with pip
If you get a no attribute error in boto3, check the version
What to do if you get an error when trying to send a message in tasks.loop () immediately after startup