簡體   English   中英

Macports和virtualenv網站程序包回退

[英]Macports and virtualenv site-packages Fallback

我已經安裝了django和python,因為該鏈接建議與Macports一起使用。 但是,我想使用virtualenv安裝更多軟件包。 我的理解是,如果我--no-site-packages傳遞給virtualenv ,那么除了安裝到虛擬環境中的所有軟件包之外,我還應該獲取當前安裝的軟件包。 這個對嗎?

例如,我已經通過macports安裝了django,然后創建了一個虛擬環境,但是我無法從該虛擬環境中導入django:

[streeter@mordecai]:~$ mkvirtualenv django-test
New python executable in django-test/bin/python
Installing setuptools............done.
...
(django-test)[streeter@mordecai]:~$ pip install django-debug-toolbar
Downloading/unpacking django-debug-toolbar
  Downloading django-debug-toolbar-0.8.4.tar.gz (80Kb): 80Kb downloaded
  Running setup.py egg_info for package django-debug-toolbar
Installing collected packages: django-debug-toolbar
  Running setup.py install for django-debug-toolbar
Successfully installed django-debug-toolbar
Cleaning up...
(django-test)[streeter@mordecai]:~$ python
Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named django
>>>

因此,我可以將程序包安裝到虛擬環境中,但不會選擇全局站點程序包。 還是我做的事情不正確/缺少什么/誤解了virtualenv工作原理?

我有Mac OS 10.6(Snow Leopard),更新了我的macports軟件包,並正在使用macports的python26(通過python_select python26 )。

編輯:

另外,我還檢查了我的macports PATH是否正確設置。 這是一些輸出:

[streeter@mordecai]:~$ python --version
Python 2.6.6
[streeter@mordecai]:~$ echo $PATH
/opt/local/bin:/opt/local/sbin:/Users/streeter/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Users/streeter/.ec2/bin
[streeter@mordecai]:~$ source dev/python-environments/test/bin/activate
(test)[streeter@mordecai]:~$ python --version
Python 2.6.1
(test)[streeter@mordecai]:~$ 

virtualenvvirtualenvwrapper都是使用pip安裝的,而不是使用macports安裝的,因為這似乎並未在/usr/local/bin/virtualenvwrapper.sh上創建要獲取源文件的文件,因此我不確定如何獲取virtualenvwrapper的別名。

如顯示的版本和日期所示,您沒有使用MacPorts Python。 (嘗試輸入/usr/bin/python2.6 ,然后輸入/opt/local/bin/python2.6 。)如果不將MacPorts bin目錄首先放在外殼執行PATH上,則僅設置MacPorts python_select並沒有好處:

$ export PATH=/opt/local/bin:$PATH

您可能需要重新創建virtualenv以確保您使用的是MacPorts Python而不是Apple提供的Python。

編輯:隨着更多的信息,我猜你的$ PATH沒有設置正確之前, 最初的采購virtualwrapper.sh描述這里 我建議您返回並按照那里的說明進行操作,確保已將virtualenvvirtualenvwrapper確實安裝到MacPorts site-packages目錄中,而不是系統Python的目錄中。 注意,MacPorts for Python 2.6當前提供的virtualenvwrapper版本是一個較舊的版本1.20; 它的shell腳本具有不同的名稱

暫無
暫無

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

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