python package installed but could not import

2019-09-14 13:30发布

I have tried to re-install and got the following message:

Requirement already satisfied: troposphere==1.8.2 in /usr/local/lib/python2.7/site-packages (from -r requirements.txt (line 13)

I checked my python version and I could see this as same:

animjain$ python -V
Python 2.7.10

When I try to import a module, get the following error:

animjain$ python
Python 2.7.10 (default, Oct 23 2015, 19:19:21) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from troposphere import Join, Ref, FindInMap
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named troposphere

2条回答
Luminary・发光体
2楼-- · 2019-09-14 14:04

In case you have multiple Python versions on your machine, install with the same Python command, so instead of:

animjain$ pip install troposphere==1.8.2

run:

animjain$ python -mpip install troposphere==1.8.2
查看更多
Juvenile、少年°
3楼-- · 2019-09-14 14:06

You should use virtualenv to install dependencies for your project. You don't need to clog global site-packages.

For example:

sudo apt-get install virtualenv
cd ~
virtualenv your_test_venv
source your_test_venv/bin/activate
pip install troposphere

After that you can use your new package.

When you want to deactivate your virtualenv you can run command deactivate

查看更多
登录 后发表回答