运行 python 脚本会产生: ImportError: no module named termcolor
我创建了一个新的虚拟环境:
$ virtualenv --no-site-packages venv --python=python3.2
然后,我激活虚拟环境并安装软件包:
$ source venv/bin/activate
$ pip install termcolor
$ python -m termcolor
这一切都很好。然后,我安装我自己的名为 Hermes 的项目,该项目使用 termcolor:
$ python setup.py install
但是当我运行安装到 virtualenv 的 bin 目录中的可执行文件时,我收到错误:
ImportError: no module named termcolor
如何安装 termcolor?
I created a new virtual environment:
$ virtualenv --no-site-packages venv --python=python3.2
Then, I activate the virtual environment and install packages:
$ source venv/bin/activate
$ pip install termcolor
$ python -m termcolor
This all works just fine. I then install my own project called Hermes which uses termcolor:
$ python setup.py install
But when I run the executable that's installed to the virtualenv's bin directory, I get an error:
ImportError: no module named termcolor
How do I install termcolor?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
错误:
表示您尚未安装 termcolor。以下是在 Ubuntu 上安装它的方法:
为您的 Linux 发行版安装它的确切命令将取决于包管理器。完成后,将其放入 python 脚本中以确保其正常工作:
该脚本应以红色打印 hello,以绿色打印 world。然后你就知道它已经安装了。
The error:
Means you have not installed termcolor. Here is how you install it for Ubuntu:
The exact command to install it for your linux distribution will depend on the package manager. When you're done with that, put this in a python script to make sure it works:
The script should print hello in red, and world in green. Then you know it is installed.
另一个 python 可执行文件必须位于路径中。您是否正在执行 sudo 或者您的 python 文件是否有
#!/usr/bin/env python
行或其他内容?尝试使用python -v
和which python
来确定您实际使用的是哪个 python。你正在运行 venv/bin/python 吗?Another python executable must be in the path. Are you doing sudo or does your python file have a
#!/usr/bin/env python
line or anything? Trypython -v
andwhich python
to figure out which python you are actually using. Are you running venv/bin/python?我最好的猜测是,您要确保您的虚拟环境在运行应用程序时处于活动状态!
抱歉,如果这听起来像愚蠢的建议,但请确保您位于虚拟环境中,以便调用的可执行文件已安装所有模块。
My best guess would be for you to make sure that your virtual env is active when you're running your app!
Sorry if it sounds like dumb advice, but make sure that you're inside the virtual env, so the executable that gets called has all the modules installed.
如果您在 Windows 中,则可以使用以下命令:
Windows 7, 32 位 [运行 cmd]
If you in windows, you can use this for example:
windows 7, 32 bit [runing your cmd]
在尝试导入之前尝试以下命令
Try below command before trying to import it