10
$ 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

呜呜呜???Ubuntu 10.10

解决方案:# chmod -R 775 /usr/local/lib/python2.6/dist-packages/ 对我有帮助。谢谢大家。

4

5 回答 5

2

最终为我工作的是:

chmod -R 775 /usr/local/lib/python2.6/dist-packages/ 
于 2012-05-21T02:47:46.020 回答
2

建议您在一般情况下使用带有 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
>>> 
于 2012-02-03T01:21:36.610 回答
0

请检查 PYTHONHOME 和 PYTHONPATH 上的以下文档:

  1. http://docs.python.org/using/cmdline.html#envvar-PYTHONHOME
  2. http://docs.python.org/using/cmdline.html#envvar-PYTHONPATH

并检查您的 PYTHONHOME。

于 2012-02-03T01:33:29.993 回答
0

检查是否可以运行python3.

于 2019-10-17T20:41:29.777 回答
0

我知道我迟到了——但我在使用 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

显然更改版本号以匹配您的目录结构!

于 2017-10-07T12:00:16.363 回答