简体   繁体   English

仅能在安装目录中导入python模块

[英]Only able to import python module inside the installation directory

I installed 64bit package of cefpython in Ubuntu 12.04 LTS ( http://code.google.com/p/cefpython/ ). 我在Ubuntu 12.04 LTS( http://code.google.com/p/cefpython/ )中安装了cefpython的64位软件包。 The problem is I am not able to run the examples. 问题是我无法运行示例。 It says no module named wx. 它说没有名为wx的模块。 But when I navigate to the directory /usr/local/lib/python2.7/dist-packages/cefpython1 and do import wx it works. 但是当我导航到目录/usr/local/lib/python2.7/dist-packages/cefpython1并导入wx时,它可以工作。 So basically I am not able to import wx outside that directory. 因此,基本上我无法在该目录之外导入wx。 I am using python interpreter on terminal. 我在终端上使用python解释器。

rishi:cefpython1 ls
cefclient          cefpython_py27.pyc  chrome.pak              examples     __init__.pyc  LICENSE.txt  wx
cefpython_py27.py  cefpython_py27.so   devtools_resources.pak  __init__.py  libcef.so     locales
rishi:cefpython1 python
Python 2.7.3 (default, Sep 26 2013, 20:03:06) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
>>> 
[2]+  Stopped                 python
rishi:cefpython1 cd ..
rishi:dist-packages python
Python 2.7.3 (default, Sep 26 2013, 20:03:06) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named wx
>>> 
KeyboardInterrupt
>>>

My PATH is as follows and PYTHONPATH is empty: installed 64bit package of cefpython in Ubuntu 12.04 LTS ( http://code.google.com/p/cefpython/ ). 我的PATH如下,PYTHONPATH为空:在Ubuntu 12.04 LTS( http://code.google.com/p/cefpython/ )中安装了64位的cefpython软件包。 The problem is I am not able to run the examples. 问题是我无法运行示例。 It says no module named wx. 它说没有名为wx的模块。 But when I navigate to the directory /usr/local/lib/python2.7/dist-packages/cefpython1 and do import wx it works. 但是当我导航到目录/usr/local/lib/python2.7/dist-packages/cefpython1并导入wx时,它可以工作。 So basically I am not able to import wx outside that directory. 因此,基本上我无法在该目录之外导入wx。 I am using python interpreter on terminal. 我在终端上使用python解释器。

rishi:dist-packages echo $PATH
/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
rishi:dist-packages echo $PYTHONPATH

rishi:dist-packages echo $PYTHONPATH

rishi:dist-packages 

Your problem here is that python has no idea where you are importing from. 您的问题是python不知道您要从哪里导入。 Refer to This post for instructions. 有关说明,请参阅此帖子 Basically, what is happening is that when you're in the directory, python knows to look for it (it looks for python files and packages in the directory). 基本上,发生的事情是,当您进入目录时,python知道要查找它(它在目录中查找python文件和软件包)。 You need to add the python libraries into the PYTHONPATH. 您需要将python库添加到PYTHONPATH中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM