我在ubuntu 12.04的主目錄下創建了一個文件夾,並保存了那裏的所有python文件。 我已經添加了我的目錄到pythonpath變量的路徑。 但它不工作。 早期文件在主目錄中時被執行,但現在它們也不會被執行。Python - PythonPath
在Ubuntu的終端 馬尼什@馬尼什 - 筆記本電腦:〜$回聲$ PYTHONPATH /家庭/馬尼什/項目:
[email protected]:~$ ls -l /home/manish/project
total 24
-rw-rw-r-- 1 manish manish 140 May 31 00:07 Connection.py
-rw-rw-r-- 1 manish manish 122 May 29 11:29 Connection.py~
-rw-rw-r-- 1 manish manish 7150 May 31 00:07 Host.py
-rw-rw-r-- 1 manish manish 7132 May 30 23:30 Host.py~
`
執行從終端:
>>> import sys
>>> sys.path
['', '/home/manish/project', '/home/manish', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PIL', '/usr/lib/python2.7/dist-packages/gst-0.10', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/pymodules/python2.7', '/usr/lib/python2.7/dist-packages/ubuntu-sso-client', '/usr/lib/python2.7/dist-packages/ubuntuone-client', '/usr/lib/python2.7/dist-packages/ubuntuone-control-panel', '/usr/lib/python2.7/dist-packages/ubuntuone-couch', '/usr/lib/python2.7/dist-packages/ubuntuone-installer', '/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol', '/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode']
從IDLE執行:
>>> import sys
>>> sys.path
['/usr/bin', '/home/manish/project', '/home/manish', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PIL', '/usr/lib/python2.7/dist-packages/gst-0.10', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/pymodules/python2.7', '/usr/lib/python2.7/dist-packages/ubuntu-sso-client', '/usr/lib/python2.7/dist-packages/ubuntuone-client', '/usr/lib/python2.7/dist-packages/ubuntuone-control-panel', '/usr/lib/python2.7/dist-packages/ubuntuone-couch', '/usr/lib/python2.7/dist-packages/ubuntuone-installer', '/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol', '/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode']
在Ubuntu的終端:
>>> import Host
>>> obj = Host()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'module' object is not callable
和主機是包含功能Python文件,我想運行一些的主機文件的功能,這就是爲什麼我想創建一個object.It包含一個類類名與文件名相同。
我也使用chmod命令爲文件授予了執行權限。
如果使用cd命令將路徑更改爲文件夾'project',文件將執行。 這裏是我做什麼
[email protected]:~$ cd project
[email protected]:~/project$ python
Python 2.7.3 (default, Apr 20 2012, 22:44:07)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> execfile('Host.py')
>>> obj = Host()
>>>
請描述你在問題中實際給出了代碼示例。例如,你可能寫道:「我添加到我的目錄到pythonpath變量的路徑是這樣的:'PYTHONPATH = pythonfiles/foo.egg'」 – kojiro
我將export PYTHONPATH =/home/manish/project:$ PYTHONPATH添加到.bashrc文件和的.profile文件 – Manish
我正在執行以下行 >>>的execfile( 'Host.py') >>> OBJ =主機() 回溯(最近通話最後一個): 文件 「」,1號線,在 NameError:名稱'主機'未定義 –
Manish