ImportError:没有名为瓶子的模块
Posted
技术标签:
【中文标题】ImportError:没有名为瓶子的模块【英文标题】:ImportError: No module named bottle 【发布时间】:2012-02-25 16:33:48 【问题描述】:$ sudo pip install bottle
Downloading/unpacking bottle
Downloading bottle-0.10.7.tar.gz (55Kb): 55Kb downloaded
Running setup.py egg_info for package bottle
Installing collected packages: bottle
Found existing installation: bottle 0.10.7
Uninstalling bottle:
Successfully uninstalled bottle
Running setup.py install for bottle
changing mode of build/scripts-2.6/bottle.py from 640 to 755
changing mode of /usr/local/bin/bottle.py to 755
Successfully installed bottle
>>> help('modules')
blahblah
bottle
blahblah
$ ls /usr/local/lib/python2.6/dist-packages/
bottle-0.10.7.egg-info bottle.py bottle.pyc
但是
$ python
Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import bottle
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named bottle
wtf??? Ubuntu 10.10
解决方案:# chmod -R 775 /usr/local/lib/python2.6/dist-packages/ 对我有帮助。谢谢大家。
【问题讨论】:
which python
说什么?
>>> print sys.path ['', '/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2', '/usr/lib /python2.6/lib-tk'、'/usr/lib/python2.6/lib-old'、'/usr/lib/python2.6/lib-dynload'、'/usr/local/lib/python2. 6/dist-packages'、'/usr/lib/python2.6/dist-packages'、'/usr/lib/python2.6/dist-packages/Numeric'、'/usr/lib/python2.6/dist -packages/PIL'、'/usr/lib/python2.6/dist-packages/gst-0.10'、'/usr/lib/pymodules/python2.6'、'/usr/lib/python2.6/dist-包/gtk-2.0'、'/usr/lib/pymodules/python2.6/gtk-2.0'、'/usr/lib/python2.6/dist-packages/wx-2.8-gtk2-unicode']
嗯。 PIP 将瓶子安装到错误的位置?
不,/usr/local/lib/python2.6/dist-packages
存在。
# chmod -R 775 /usr/local/lib/python2.6/dist-packages/ 对我有帮助。谢谢大家。
【参考方案1】:
检查您是否可以运行python3
。
【讨论】:
【参考方案2】:我知道我迟到了 - 但我在使用 python 命令时遇到了问题,并且我的 bottle.py 模块位于我的 3.x lib 目录中。
我只是将 python3.x 中的 bottle.py 的符号链接扔到我当前的 2.x 目录中:
sudo ln -s ~/.local/lib/python3.5/site-packages/bottle.py /usr/local/lib/python2.7/dist-packages/bottle.py
显然更改版本号以匹配您的目录结构!
【讨论】:
【参考方案3】:最终对我有用的是:
chmod -R 775 /usr/local/lib/python2.6/dist-packages/
【讨论】:
【参考方案4】:一般来说,建议您在 python 中使用 virtualenv,但我会说尤其是在 Web 开发中。
使用 virtualenv 会发生什么?
$ sudo pip install virtualenv virtualenvwrapper
$ sudo cat >> ~/.bashrc << EOF
# virtualenvwrapper setup
export WORKON_HOME=~/.virtualenvs
export VIRTUALENVWRAPPER_VIRTUALENV_ARGS='--no-site-packages --python=python2.6'
source /usr/local/bin/virtualenvwrapper.sh
EOF
$ source ~/.bashrc
$ mkvirtualenv test
$ pip install bottle
$ python
>>> import bottle
因为我明白了:
$ python
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24)
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import bottle
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named bottle
>>>
$ mkvirtualenv test
Running virtualenv with interpreter /usr/bin/python2.6
New python executable in test/bin/python2.6
Also creating executable in test/bin/python
Please make sure you remove any previous custom paths from your /home/hughdbrown/.pydistutils.cfg file.
Installing setuptools.............................done.
Installing pip...............done.
virtualenvwrapper.user_scripts creating /home/hughdbrown/.virtualenvs/test/bin/predeactivate
virtualenvwrapper.user_scripts creating /home/hughdbrown/.virtualenvs/test/bin/postdeactivate
virtualenvwrapper.user_scripts creating /home/hughdbrown/.virtualenvs/test/bin/preactivate
virtualenvwrapper.user_scripts creating /home/hughdbrown/.virtualenvs/test/bin/postactivate
virtualenvwrapper.user_scripts creating /home/hughdbrown/.virtualenvs/test/bin/get_env_details
$ pip install bottle
Downloading/unpacking bottle
Downloading bottle-0.10.7.tar.gz (55Kb): 55Kb downloaded
Running setup.py egg_info for package bottle
Installing collected packages: bottle
Running setup.py install for bottle
changing mode of build/scripts-2.6/bottle.py from 644 to 755
changing mode of /home/hughdbrown/.virtualenvs/test/bin/bottle.py to 755
Successfully installed bottle
Cleaning up...
$ python
Python 2.6.6 (r266:84292, Mar 25 2011, 19:24:58)
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import bottle
>>>
【讨论】:
Traceback(最近一次调用最后一次):文件“export WORKON_HOME=~/.virtualenvs source /usr/local/bin/virtualenvwrapper.sh
您正在运行 Ubuntu,但没有 ~/.bashrc?采购 .bashrc 失败并出现错误?
或者可能 virtualenvwrapper 正在安装到 /usr/local/bin
中,而您在安装到 /usr/local
时遇到了一个一般问题,而 chmod-ing /usr/local/lib/python2.6/dist-packages
没有解决这个问题。【参考方案5】:
请检查 PYTHONHOME 和 PYTHONPATH 的以下文档:
-
http://docs.python.org/using/cmdline.html#envvar-PYTHONHOME
http://docs.python.org/using/cmdline.html#envvar-PYTHONPATH
并检查您的 PYTHONHOME。
【讨论】:
链接可能会改变,对于非 python 用户来说,你不清楚你在画什么区别,或者这如何回答这个问题。以上是关于ImportError:没有名为瓶子的模块的主要内容,如果未能解决你的问题,请参考以下文章
ImportError:没有名为 ghostscript 的模块
ImportError:没有名为 pynotify 的模块。安装模块时
ImportError:没有名为 websocket 的模块