2013-05-05 94 views
6

我正在嘗試安裝金字塔應用程序 - 比方說test_app。在虛擬環境中,它被安裝爲test-app(pip凍結輸出顯示它爲test-app==0.0)。爲什麼PIP將下劃線轉換爲破折號

因此,我無法導入包。

我該如何解決這個問題?

更多信息: http://mail.python.org/pipermail/distutils-sig/2011-August/017935.html

我使用PIP版本1.3.1

setup.py:

import os 

from setuptools import setup, find_packages 

here = os.path.abspath(os.path.dirname(__file__)) 
README = open(os.path.join(here, 'README.txt')).read() 
CHANGES = open(os.path.join(here, 'CHANGES.txt')).read() 

requires = [ 
    'pyramid', 
    'pyramid_debugtoolbar', 
    'waitress', 
    ] 

setup(name='test_app', 
     version='0.0', 
     description='test_app', 
     long_description=README + '\n\n' + CHANGES, 
     classifiers=[ 
     "Programming Language :: Python", 
     "Framework :: Pyramid", 
     "Topic :: Internet :: WWW/HTTP", 
     "Topic :: Internet :: WWW/HTTP :: WSGI :: Application", 
     ], 
     author='', 
     author_email='', 
     url='', 
     keywords='web pyramid pylons', 
     packages=find_packages(), 
     include_package_data=True, 
     zip_safe=False, 
     install_requires=requires, 
     tests_require=requires, 
     test_suite="test_app", 
     entry_points="""\ 
     [paste.app_factory] 
     main = test_app:main 
     """, 
    ) 

UPDATE:

總結的調查結果至今:

  • pip將軟件包名稱報告爲test-app是正常的。
  • 雞蛋鏈接指向你的虛擬env root是不正常的。
  • 但是,.egg-info文件是在您的虛擬env根目錄中創建的,並指出將該目錄用作蛋根。
+0

迄今爲止的總結:'develop'命令在虛擬env根目錄下創建一個'.egg-info'目錄,'.egg-link'文件指向同一個根目錄。這是導入錯誤的原因。 'pip'將軟件包名稱報告爲'test-app'的事實是正常的。 – 2013-05-05 17:24:44

+0

@MartijnPieters我已經解決了這個問題。看到我的答案。 – treecoder 2013-05-05 19:36:54

回答

4

所以,最後經過大量的擺弄,我發現瞭解決方案 - 這是令人討厭的簡單。

我正在使用virtualenv並正在開發模式下安裝軟件包。

我從錯誤的位置安裝軟件包。原來,您運行python setup.py develop的位置(目錄)確實是進入.egg-link文件的位置(目錄)。

您應該將程序包安裝到您的代碼所在的位置的虛擬環境中。

因此,舉例來說,假設你的代碼駐留在 '/ A/B' 和你的virtualenv ENV是 '/ X/Y/env的',那麼你應該安裝該軟件包是這樣的:

$ cd /a/b 
$ /x/y/env/bin/python setup.py develop 

這將正確安裝包裝。

因此,' - '和'_'問題不是問題,您應該注意從develop模式下安裝軟件包的位置。

+0

FWIW,我已經開始使用'pip install -e .'來代替'python setup.py develop'。它們在功能上是等效的,但pip的版本具有較少的錯誤。 – 2016-06-05 20:35:00

相關問題