这是Python路径问题吗?

时间:2017-09-11 03:42:18

标签: python

我对我的Python路径是否设置正确感到困惑。我在企业环境中使用Ubuntu所以我一直在--user环境中安装virtualenv设置的软件包/模块(我没有管理员或sudo权限)。

(my_env)xx@xx:~/environments$ pip install --user browsercookie
Requirement already satisfied (use --upgrade to upgrade): browsercookie in /home/myUsername/.local/lib/python2.7/site-packages

但是当我运行我的文件时,我得到了:

ImportError: No module named browsercookie

其他细节:

(my_env)xx@xx:~/environments$ which python
/usr/share/anaconda/bin/python

这是我在安装browsercookie时收到的消息:

(my_env)xx@xx:~/environments$ python <where setup files are>/setup.py install --user
/usr/share/anaconda/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'install_requires'
  warnings.warn(msg)
running install
running build
running build_py
package init file './__init__.py' not found (or not a regular file)
copying ./my_file.py -> build/lib/browsercookie
package init file './__init__.py' not found (or not a regular file)
running install_lib
copying build/lib/browsercookie/my_file.py -> /home/myUsername/.local/lib/python2.7/site-packages/browsercookie
byte-compiling /home/myUsername/.local/lib/python2.7/site-packages/browsercookie/my_file.py to my_file.pyc
running install_egg_info
Writing /home/myUsername/.local/lib/python2.7/site-packages/browsercookie-0.7.1-py2.7.egg-info

和...

(my_env)xx@xx:~/environments$ which pip
/usr/share/anaconda/bin/pip
(my_env)xx@xx:~/environments$ pip install browsercookie
Requirement already satisfied (use --upgrade to upgrade): browsercookie in /home/myUsername/.local/lib/python2.7/site-packages

新环境详情:

xx@xx:~/environments$ virtualenv new_env
New python executable in new_env/bin/python
Installing distribute.............................................................................................................................................................................................done.
Installing pip...............done.
xx@xx:~/environments$ source new_env/bin/activate
(new_env)xx@xx:~/environments$ which virtualenv
/usr/bin/virtualenv
(new_env)xx@xx:~/environments$ which pip
/home/username/environments/new_env/bin/pip
(new_env)xx@xx:~/environments$ which python
/home/username/environments/new_env/bin/python

有人能指出我正确的方向吗?

1 个答案:

答案 0 :(得分:0)

首先你需要升级你的 pip 安装程序:

pip3 install --upgrade setuptools pip

安装包后:

 pip3 install browser-cookie3

并使用python3执行