簡體   English   中英

如何在Python 2.6中使用帶有pth文件的自定義站點包?

[英]How to use a custom site-package using pth-files for Python 2.6?

我正在嘗試設置自定義站點包目錄(Windows Vista上為Python 2.6)。 例如,目錄應為“〜\\ lib \\ python2.6”(C:\\ Users \\ wierob \\ lib \\ python2.6)。 因此,調用“ setup.py install”應將軟件包復制到C:\\ Users \\ wierob \\ lib \\ python2.6。

請按照此處的說明進行操作:

我已經在Python安裝的site-packages目錄(C:\\ Python26 \\ Lib \\ site-packages)中創建了一個pth文件。 該文件包含一行:

import os, site; site.addsitedir(os.path.expanduser('~/lib/python2.6'))

另外,我的主目錄(C:\\ Users \\ wierob)中有一個pydistutils.cfg,其中包含:

[install]
install_lib = ~/lib/python2.6
install_scripts = ~/bin

當我運行“ setup.py install”時,出現以下錯誤消息:

C:\Users\wierob\Documents\Python\workspace\rsreader>setup.py install
running install
Checking .pth file support in C:\Users\wierob\lib\python2.6\
C:\Python26\pythonw.exe -E -c pass
TEST FAILED: C:\Users\wierob\lib\python2.6\ does NOT support .pth files
error: bad install directory or PYTHONPATH

You are attempting to install a package to a directory that is not
on PYTHONPATH and which Python does not read ".pth" files from.  The
installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:

    C:\Users\wierob\lib\python2.6\

因此,似乎pth文件不起作用。 雖然,如果我輸入

site.addsitedir(os.path.expanduser('~/lib/python2.6'))

在交互式python會話中,目錄已成功添加到sys.path。

有任何想法嗎? 謝謝。

如果使用帶有BOM的UTF-8編碼,則pth文件似乎會被忽略。

在沒有BOM的情況下將pth文件保存在ANSI或UTF-8中是可行的。

根據文檔,您應該將路徑放入.pth文件,因此可以輸入:

C:\Users\wierob\lib\python2.6

將工作

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM