简体   繁体   中英

Python cannot find module

So I've updated some of my pies. That implied that one of them, on which I had some python scripts, got demoted, and a new one arose in it's place. So I've moved my scripts.

One script needs the pastebin module. I have taken to install pastebin. With pip.

Now pip, says everything is installed successfully. I beg to differ. Running my script I get a

ImportError: No module named pastebin

pip list says

Pastebin (1.1.1)
pip (7.1.2)
setuptools (19.1.1)
wheel (0.26.0)

now, if I write pyt and double tap the tab key I see

python python2 python2.7

and for pip

pip pip2 pip2.7
python --version

says

Python 2.7.9

So, where in Gods name is my module installed, and how can I get python to see it?

Needless to say, I've reinstalled both python and pip multiple times. This is on a fresh install of raspbian.

EDIT 1

So, running

python -c "import site; print(site.getsitepackages())" 

I get

['/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages'] 

/usr/local/lib/python2.7/dist-packages contains Pastebin.

The other one doesn't

Running

python -c "import sys; print(sys.path)" 

I get

['', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-arm-linux-gnueabihf', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages'] 

Edit2 Running

help('modules') 

I get a list of modules which doesn't contain pastebin. And I've already installed a virtualenv for my project, in which I've installed pastebin with pip

try this:

Download pastebin from here: https://pypi.python.org/pypi/Pastebin/1.1.1

python setup.py install

Having installed/reinstalled python and pip, we first want to make sure that pip is installing to the same site-packages location that your python 2.7.9 is using. Running python -c "import site; print(site.getsitepackages())" from the command line will tell you where your copy of python is searching for modules. Check that directory to see if pastebin is inside.

Alternatively, we can run python -c "import sys; print(sys.path)" to see every directory that python searches.

Edit

Running python -c "import pastebin" in command line will check to see if the python interpreter your command window is using can import the package. If there is no error here, then you are probably using a different interpreter to run your script (when the ImportError appears). The other interpreter will need to be reconfigured to search in the same directory for modules.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM