简体   繁体   中英

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/ ). The problem is I am not able to run the examples. It says no module named wx. But when I navigate to the directory /usr/local/lib/python2.7/dist-packages/cefpython1 and do import wx it works. So basically I am not able to import wx outside that directory. I am using python interpreter on terminal.

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/ ). The problem is I am not able to run the examples. It says no module named wx. But when I navigate to the directory /usr/local/lib/python2.7/dist-packages/cefpython1 and do import wx it works. So basically I am not able to import wx outside that directory. I am using python interpreter on terminal.

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. 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). You need to add the python libraries into the PYTHONPATH.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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