Investigation when import cannot be done with python

Even numpy can't be imported. Confirmation when it is included in pip list, but ... When you have to build an environment on a messy machine.

python path

First from here.

ls -l `which python3`

You can see where you are referring to when you type the command python3. Since there may be multiple pythons unintentionally included, Make sure it matches what you want to use.

pip path

pip3 --version
ls -l `which pip3`

Confirmation of module installation

pip3 show [Module name]

For example, in the case of numpy

pip3 show numpy

If installed, pay attention to Location.

Name: numpy
Version: 1.18.1
Summary: NumPy is the fundamental package for array computing with Python.
Home-page: https://www.numpy.org
Author: Travis E. Oliphant et al.
Author-email: None
License: BSD
Location: /usr/local/lib/python3.7/site-packages

python system path

python3

Enter to enter python3. Then execute the following 3 lines

import sys
import pprint
pprint.pprint(sys.path)

When the path is displayed, press control + D to exit. Check if the location of the module is here.

If not, check the environment variable PYTHONPATH

Check the environment variable PYTHONPATH

echo $PYTHONPATH

If you write the location setting of the module here It works for the time being.

If bash,

export PYTHONPATH=[Module Location]

If csh,

setenv PYTHONPATH [Module Location]

Then, put it in the environment variable. Check with ʻecho $ PYTHONPATH`.

However, restarting the terminal resets the environment variables. If you want to make it permanent, add it to bash_profile or cshrc. (Please check the environment variable settings separately)

retry

python3 
import [Module name]

I will try.

Recommended Posts

Investigation when import cannot be done with python
When import matplotlib.pyplot cannot be done in pyenv-virtualenv environment
Solution when the image cannot be displayed with tkinter [python]
Python modules with "-(hyphen)" cannot be removed
Project cannot be created with Python3.5 (Windows) + django1.7.1
When Html cannot be output with Jupyter Notebook
When contour map cannot be drawn with APLpy
"Temporary solution" when pip cannot be updated [Python]
Python environment settings (virtualenv + pip cannot be done)
Measures that pip install cannot be done with pycharm or import ssl cannot be done
Import tsv with Python
Python note: When the pip command cannot be used
Import libraries that cannot be pip installed with PyCharm
[android] When AVD cannot be used with permission denied
Causes when python version cannot be changed using pyenv
What to do when "cannot import name xxx" [Python]
Import vtk with brew python
Error when playing with python
When USB cannot be formatted
When pydub cannot be installed
Options when installing libraries that cannot be piped with pyenv
Master the type in Python? (When should type check be done)
Video cannot be loaded with Spyder in Python development environment
When Times New Roman cannot be used with matplotlib (Ubuntu)
A memorandum (masOS) that import tkinter could not be done with python installed from pyenv
TensorFlow 2.2 can't be installed with Python 3.8!
Working with LibreOffice in Python: import
(Note) Be careful with python argparse
[Python] Be careful when using print
When matplotlib doesn't work with python2.7
When using MeCab with virtualenv python
Precautions when using six with Python 2.5
[Python] Format when to_csv with pandas
Be careful of LANG for UnicodeEncodeError when printing Japanese with Python 3
python + SCOOP distributed computing cannot be done on a Windows PC
Parallel computing (pathos) when dealing with objects that cannot be pickled
Snippet when searching all bits with python
Note when creating an environment with python
Precautions when solving DP problems with Python
When I import TensorFlow to Python, I get "Import Error: DLL load failed: The specified module cannot be found."
Address to the bug that node.surface cannot be obtained with python3 + mecab
Items that cannot be imported with sklearn
Be careful when running CakePHP3 with PHP7.2
Solution when aws-cli cannot be executed on Mac virtual environment (after installing Python 3.8)
When using PyQtGraph with Python Pyside, pay attention to the order of import
Correspondence memo when the direction key cannot be used on the python command line
De-VBA Excel tool! Eliminate VBA tool with Python in environment where Python cannot be installed
Error when installing a module with Python pip
[Linux] When "| (pipe)" cannot be hit on CentOS7
Personal tips when doing various things with Python 3
Python> Run with run-time arguments> Use import argparse
Precautions when dealing with control structures in Python 2.6
No module named'distutils.util' cannot be used with get-pip.py
A memo when creating a python environment with miniconda
Character encoding when dealing with files in Python 3
[python] [vscode] When you get angry with space-tab-mixed
Download and import files with Splunk external python
[Web development with Python] Precautions when saving cookies
Materials to read when getting started with Python
PIL cannot be installed by virtualenv with pyenv
Be careful when working with gzip-compressed text files