如何创造一个纯粹的'的virtualenv?

时间:2016-10-31 22:05:13

标签: python macos dependencies virtualenv

我正在尝试创建virtualenv并仔细跟踪所有依赖项。我用这种方式创建了env:

virtualenv --no-site-packages purenv

cd purenv
source bin/activate

然后运行这个python脚本:

url = "http://localhost:6543/foo/",

hdrz = {
    "Accept" : "text/html",
    "account-code":"foo1234",
    'Content-Type': 'application/json'
}
request = urllib2.Request(url, headers=hdrz)

我收到此错误:

  File "foo.py", line 10, in <module>
    request = urllib2.Request(url, headers=hdrz)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 229, in __init__
    self.__original = unwrap(url)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 1075, in unwrap
    url = url.strip()
AttributeError: 'tuple' object has no attribute 'strip'

which python
/Users/foo.bar/workspace/purenv/bin/python

所以,我使用安装到virtualenv的python,但错误来自virtualenv之外(/System/Library/Frameworks/...而不是purenv/lib/python2.7/site-packages...等)。

如何创建一个不调用外部文件的virtualenv?

1 个答案:

答案 0 :(得分:1)

变化:

url = "http://localhost:6543/foo/",

要:

url = "http://localhost:6543/foo/"

你发送的是元组,而不是str。 抱歉英文不好。