在windows 7上的virtualenv返回AssertionError。

时间:2021-07-26 02:13:42

Having trouble with virtualenv on Windows 7.

在Windows 7上遇到了virtualenv的麻烦。

I run:

我运行:

virtualenv _testenv

It returns:

它返回:

Traceback (most recent call last):
  File "C:\Python27\Scripts\virtualenv-script.py", line 9, in <module>
    load_entry_point('virtualenv==1.5.2', 'console_scripts', 'virtualenv')()
  File "C:\Python27\lib\site-packages\virtualenv.py", line 558, in main
    prompt=options.prompt)
  File "C:\Python27\lib\site-packages\virtualenv.py", line 647, in create_environment
    site_packages=site_packages, clear=clear))
  File "C:\Python27\lib\site-packages\virtualenv.py", line 771, in install_python
    copy_required_modules(home_dir)
  File "C:\Python27\lib\site-packages\virtualenv.py", line 725, in copy_required_modules
    dst_filename = change_prefix(filename, dst_prefix)
  File "C:\Python27\lib\site-packages\virtualenv.py", line 710, in change_prefix
    (filename, prefixes)
AssertionError: Filename c:\Python27\Lib\os.py does not start with any of these prefixes: ['C:\\Python27']

I have the following environment variables:

我有以下环境变量:

PYTHONHOME=C:\Python27
PYTHONPATH=c:\Python27;c:\Python27\Lib
PYTHONSTARTUP=C:\Users\Larry\.pythonrc
PATH=%PYTHONHOME%\;%PYTHONHOME%\Scripts;etc

Installed ActiveState Python:

ActiveState的Python安装:

ActivePython 2.7.2.5 (ActiveState Software Inc.) based on
Python 2.7.2 (default, Jun 24 2011, 12:21:10) [MSC v.1500 32 bit (Intel)] on win32

I updated the PYTHONPATH=C:\Python27;C:\Python27\Lib Still looking for a solution, I found and removed AppData/Python*. Reinstalled Python and now have a different error:

我更新了PYTHONPATH=C:\Python27;C:\Python27\Lib仍在寻找解决方案,我找到并删除了AppData/Python*。重新安装Python,现在有一个不同的错误:

C:\xbz>virtualenv _t
PYTHONHOME is set.  You *must* activate the virtualenv before using it
Overwriting _t\Lib\site.py with new content
New python executable in _t\Scripts\python2.7.exe
Not overwriting existing python script _t\Scripts\python.exe (you must use _t\Scripts\python2.7.exe)
Overwriting _t\Lib\distutils\__init__.py with new content
Installing setuptools..............
  Complete output from command C:\xbz\_t\Scripts\python2.7.exe -c "#!python
\"\"\"Bootstrap setuptoo...


" --always-copy -U setuptools:
  Traceback (most recent call last):
  File "<string>", line 278, in <module>
  File "<string>", line 210, in main
  File "<string>", line 132, in download_setuptools
  File "C:\Python27\Lib\urllib2.py", line 94, in <module>
    import httplib
  File "C:\Python27\Lib\httplib.py", line 71, in <module>
    import socket
  File "C:\Python27\Lib\socket.py", line 47, in <module>
    import _socket
ImportError: No module named _socket
----------------------------------------
...Installing setuptools...done.
Traceback (most recent call last):
  File "C:\Python27\Scripts\virtualenv-script.py", line 9, in <module>
    load_entry_point('virtualenv==1.5.2', 'console_scripts', 'virtualenv')()
  File "C:\Python27\lib\site-packages\virtualenv.py", line 558, in main
    prompt=options.prompt)
  File "C:\Python27\lib\site-packages\virtualenv.py", line 654, in create_environment
    install_setuptools(py_executable, unzip=unzip_setuptools)
  File "C:\Python27\lib\site-packages\virtualenv.py", line 384, in install_setuptools
    _install_req(py_executable, unzip)
  File "C:\Python27\lib\site-packages\virtualenv.py", line 360, in _install_req
    cwd=cwd)
  File "C:\Python27\lib\site-packages\virtualenv.py", line 624, in call_subprocess
    % (cmd_desc, proc.returncode))
OSError: Command C:\xbz\_t\Scripts\python2.7.exe -c "#!python
\"\"\"Bootstrap setuptoo...




" --always-copy -U setuptools failed with error code 1

I hacked Lib/socket.py and inserted:

我砍Lib /插座。py和插入:

import sys
sys.path = ['', 'C:\\Python27\\lib\\site-packages\\dotcloud-0.3.1-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\dotcloud.cli-0.3.1-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\flask-0.7dev_20110622-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\werkzeug-0.6.2-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\gunicorn-0.12.2-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\wtforms-0.6.3-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\repoze.browserid-0.3-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\paste-1.7.5.1-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\django_pjax-1.0-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\paramiko-1.7.7.1-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\pycrypto-2.4.1-py2.7-win32.egg', 'C:\\Python27', 'C:\\Python27\\Lib', 'C:\\Windows\\system32\\python27.zip', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib\\plat-win', 'C:\\Python27\\lib\\lib-tk', 'C:\\Python27\\lib\\site-packages', 'C:\\Python27\\lib\\site-packages\\PIL', 'C:\\Python27\\lib\\site-packages\\win32', 'C:\\Python27\\lib\\site-packages\\win32\\lib', 'C:\\Python27\\lib\\site-packages\\Pythonwin', 'C:\\Python27\\lib\\site-packages\\setuptools-0.6c11-py2.7.egg-info', 'C:\\Python27\\Scripts', 'C:\\Python27\\Lib\\site-packages\\django\\bin']

Above

以上

import _socket

The reason was that I was able to import socket from straight python prompt! So stuffed my existing path. I haven't narrowed down exactly which directory made it happy. It at least will reveal to someone else why I am getting the error without it.

原因是我能够从直的python提示符导入套接字!填充了我现有的路径。我还没有精确地缩小哪个目录能让它快乐。它至少会告诉别人为什么我没有它的错误。

Ideas? Suggestions? Thank you. :)

想法吗?建议吗?谢谢你!:)


I hacked Lib/socket.py and inserted:

我砍Lib /插座。py和插入:

import sys
sys.path.append('C:\\Python27\\DLLs')

Above

以上

import _socket

13 个解决方案

#1


23  

3 year old question, but hopefully this answer can still help someone. Rather than setting the environment variables (which mysteriously didn't work for me), you can pass the path to your Python installation when setting up the virtual environment. In Windows, you have to path out to python.exe, but it seems that in Linux/OS X you just path to the folder. Examples:

3岁的问题,但希望这个答案仍然能帮助别人。您可以在设置虚拟环境时将路径传递给您的Python安装,而不是设置环境变量(这对我来说不是很有用)。在Windows中,您必须选择python。exe,但是在Linux/OS X中,你只需要路径到文件夹。例子:

Windows:

窗口:

virtualenv -p <PATH TO PYTHON.EXE> venv

Linux/Mac:

Linux / Mac:

virtualenv -p </user/path/to/python> venv

Both create a virtual environment in subfolder "venv" in current directory.

两者都在当前目录下的子文件夹“venv”中创建虚拟环境。

#2


11  

Try to set PYTHONPATH to PYTHONPATH=C:\Python27;C:\Python27\Lib (uppercase C at the start).

尝试将PYTHONPATH设置为PYTHONPATH=C:\Python27;C:\Python27\Lib(大写C开头)。

This can be done at the command prompt by typing set PYTHONPATH=C:\Python27;C:\Python27\Lib.

在命令提示符下,可以通过键入set PYTHONPATH=C:\Python27;C:\Python27\Lib。

PYTHONPATH will revert back to whatever it previously was once that command prompt window is closed.

当命令提示窗口关闭时,PYTHONPATH将恢复到以前的任何内容。

#3


4  

For the _socket error, change your pythonpython path to:

对于_socket错误,更改pythonpython路径到:

PYTHONPATH=C:\Python27;C:\Python27\Lib;C:\Python27\DLLs

#4


3  

I have added

我已经添加了

if is_win:    
        prefixes.append('C:\PYTHON27')    

to virtualenv.py and it works.

virtualenv。py和它的工作原理。

#5


3  

There is similar problem currently that shows error:

目前有类似的问题显示错误:

AssertionError: Filename C:\Python27\Lib\os.py does not start with any of 
these prefixes: ['C:\\python27']

The difference is in 'C:\python27' being lower case. So the problem manifest itself in that you can not install new virtualenv or make a nested virtualenvs (we do it for testing sometimes). The cause is in the conent of the PYTHONPATH

区别在于“C:\python27”是小写字母。因此,问题出现在您不能安装新的virtualenv或创建嵌套的virtualenv(我们有时会进行测试)。原因就在PYTHONPATH中。

PYTHONPATH=C:\Python27;C:\Python27\Lib

For some reason sys.path in virtualenv.py will return c:\python27, but path to required modules will come form the PYTHONPATH and start with 'C:\Python27\Lib', hence the assertion error.

出于某种原因系统。在virtualenv路径。py将返回c:\python27,但是所需模块的路径将会从PYTHONPATH开始,并以“c:\python27 \Lib”开头,因此会出现断言错误。

Long story short, just unset the PYTHONPATH.

长话短说,只是打开了PYTHONPATH。

#6


2  

Its strange but from the error message

这很奇怪,但从错误的信息。

AssertionError: Filename c:\Python27\Lib\os.py does not start with any of these prefixes: ['C:\\Python27']

It seems, it expects the path-name for the file os.py to start with upper case 'C' and the prefix sanity check is case sensitive.

看起来,它期望文件os的路径名。py从大写字母“C”开始,前缀“完整性检查”是区分大小写的。

As the path to the library is derived from PYTHONPATH and in your case the drive letter is in lower case, it seems logical to change it to upper case to resolve the issue.

由于从PYTHONPATH派生出了通向库的路径,在您的情况下,驱动器字母是小写的,因此将其更改为大写以解决问题似乎是合乎逻辑的。

like

就像

PYTHONPATH=C:\Python27;C:\Python27\Lib

#7


1  

I hate "summary" answers, but as I just went through a very similar issue I thought I would post my solution here as well which draws from several of these answers.

我讨厌“总结”的答案,但当我刚刚经历了一个非常类似的问题时,我想我也会在这里把我的解决方案从几个答案中引出来。

The assert error was caused because I did not have a PYTHONPATH environment variable setup.

断言错误是由于我没有使用PYTHONPATH环境变量设置造成的。

The socket error was caused because I did not include the PythonXX\DLLs folder.

套接字错误是由于我不包括PythonXX\DLLs文件夹造成的。

The full PYTHONPATH environment variable should look follows:

完整的PYTHONPATH环境变量应该是:

PYTHONPATH=C:\Python27;C:\Python27\Lib;C:\Python27\DLLs

#8


1  

This is an error already submitted to the Python development team: https://github.com/pypa/virtualenv/pull/697

这是一个已经提交给Python开发团队的错误:https://github.com/pypa/virtualenv/pull/697。

In the meanwhile why not just change the Python installation folder name to (ptyhon27) to make the assertion work, or if you feel more confortable with that just reinstall python using the alternative location. It works with no issue.

在此期间,为什么不只是将Python安装文件夹名称改为(ptyhon27)来进行断言工作,或者,如果您觉得可以使用替代的位置重新安装Python,您会感到更舒服。它没有问题。

#9


1  

You can try the following (supppose your python is in global path):

您可以尝试以下方法(您的python是在全局路径中):

python -m virtualenv [foldername]

This works for me, Win 10, virtualenv 15.1.0

这对我来说很有效,Win 10, virtualenv 15.1.0。

I get it from this video, it will excute the python lib instead of calling windows exe.

我从这段视频中得到它,它将会把python库去掉,而不是调用windows exe。

#10


0  

I also ran into this problem on Windows 7. My Python27 installation was under C:\Program Files, which obviously contains a space in the path. So, on a separate Windows 7 system that did not contain Python, I did a fresh install of Python27 under C:\Python27 (the default installation path), followed by an install of setuptools (for easy_install).

我在Windows 7上也遇到了这个问题。我的Python27安装在C:\程序文件中,它显然包含了路径中的一个空间。因此,在一个不包含Python的单独的Windows 7系统中,我在C:\Python27(默认的安装路径)下重新安装了Python27,然后安装了setuptools(用于easy_install)。

Afterwards, I was able to install virtualenv CLEANLY without the above assertion error (I used easy_install).

之后,我能够在没有上述断言错误的情况下,轻松地安装virtualenv(我使用easy_install)。

I know that the OP's system is already using the default path, but I thought I would add my experience here as a possible solution for certain specific cases.

我知道OP的系统已经在使用默认路径,但是我想我应该在这里添加我的经验作为某些特定案例的可能解决方案。

#11


0  

This issue is presumably a hangover from other more case-sensitive file systems.

这个问题大概是其他区分大小写的文件系统遗留下来的问题。

Complete solution:

完整的解决方案:

  1. Read the error message from virtualenv. Remember the part where it says "does not start with any of these prefixes: ['C:\\Python27']".

    从virtualenv中读取错误消息。记住它所说的“不以这些前缀开头的部分:['C:\\Python27']”。

  2. Edit PYTHONPATH, or create it if you don't have one (Start+Break, Advanced system settings, Environment Variables). It shouldn't matter if it's a user variable or a system variable, unless you plan to switch user accounts.

    编辑PYTHONPATH,或者创建它,如果您没有一个(启动+中断,高级系统设置,环境变量)。它是一个用户变量还是一个系统变量都不重要,除非您计划切换用户帐户。

  3. Make the case match the error message. BOTH the drive letter AND the folder name must match (presumably intermediate folders as well, if you didn't install to C:\Python27). You can ignore the double backslash, one is fine.

    使情况与错误消息匹配。驱动器号和文件夹名称必须匹配(如果您没有安装到C:\Python27),则必须匹配(可能是中间文件夹)。你可以忽略双反斜杠,一个很好。

The only change I made to fix the bug was as follows. The change should take effect for any new command / terminal sessions (close your open cmd.exe / powershell / etc. windows).

我为修复bug所做的唯一更改是如下所示。更改将对任何新的命令/终端会话生效(关闭您的开放cmd)。exe / powershell / etc. windows)。

  • Old state: PYTHONPATH = C:\PYTHON27;C:\PYTHON27\LIB;C:\PYTHON27\DLLS

    Old state: PYTHONPATH = C:\PYTHON27;C:\PYTHON27\LIB;C:\PYTHON27\ dll。

  • New state: PYTHONPATH = C:\Python27;C:\Python27\LIB;C:\Python27\DLLS

    新状态:PYTHONPATH = C:\Python27;C:\Python27\LIB;C:\Python27\DLLS。

If you have any other items in your PYTHONPATH, you might as well change those too, but it probably won't affect virtualenv's ability to run.

如果您在PYTHONPATH中有任何其他项,您也可以更改它们,但它可能不会影响virtualenv的运行能力。

#12


0  

Change "virtualenv.py" --> change_prefix with:

virtualenv变化”。py”——> change_prefix:

def change_prefix(filename, dst_prefix):
  ...
 prefixes = sorted(prefixes, key=len, reverse=True)
 filename = str(os.path.abspath(filename))[0].lower() + str(os.path.abspath(filename))[1:]
 for src_prefix in prefixes:
    if filename.startswith(src_prefix):
        _, relpath = filename.split(src_prefix, 1)
        if src_prefix != os.sep: # sys.prefix == "/"
            assert relpath[0] == os.sep
            relpath = relpath[1:]
        return join(dst_prefix, relpath)
 assert False, "Filename %s does not start with any of these prefixes: %s" % \
    (filename, prefixes)

  ...

#13


0  

I had the same assertion error from a slightly different cause. The error was does not start with any of these prefixes: ['C:\\python27'] and note the lowercase "p". The actual folder names all use capital-P Python27. All the prefixes in PTYHONPATH were correct. However I had entered the PYTHONHOME variable as C:\python27 and although this was fine for Python, it caused the error in virtualenv.

我从一个稍微不同的原因中得到了相同的断言错误。错误不是从这些前缀开始的:['C:\\python27']和注意小写的“p”。实际的文件夹名称都使用大写- p Python27。PTYHONPATH的所有前缀都是正确的。然而,我输入了PYTHONHOME变量作为C:\python27,尽管这对Python来说很好,但是它在virtualenv中引起了错误。

#1


23  

3 year old question, but hopefully this answer can still help someone. Rather than setting the environment variables (which mysteriously didn't work for me), you can pass the path to your Python installation when setting up the virtual environment. In Windows, you have to path out to python.exe, but it seems that in Linux/OS X you just path to the folder. Examples:

3岁的问题,但希望这个答案仍然能帮助别人。您可以在设置虚拟环境时将路径传递给您的Python安装,而不是设置环境变量(这对我来说不是很有用)。在Windows中,您必须选择python。exe,但是在Linux/OS X中,你只需要路径到文件夹。例子:

Windows:

窗口:

virtualenv -p <PATH TO PYTHON.EXE> venv

Linux/Mac:

Linux / Mac:

virtualenv -p </user/path/to/python> venv

Both create a virtual environment in subfolder "venv" in current directory.

两者都在当前目录下的子文件夹“venv”中创建虚拟环境。

#2


11  

Try to set PYTHONPATH to PYTHONPATH=C:\Python27;C:\Python27\Lib (uppercase C at the start).

尝试将PYTHONPATH设置为PYTHONPATH=C:\Python27;C:\Python27\Lib(大写C开头)。

This can be done at the command prompt by typing set PYTHONPATH=C:\Python27;C:\Python27\Lib.

在命令提示符下,可以通过键入set PYTHONPATH=C:\Python27;C:\Python27\Lib。

PYTHONPATH will revert back to whatever it previously was once that command prompt window is closed.

当命令提示窗口关闭时,PYTHONPATH将恢复到以前的任何内容。

#3


4  

For the _socket error, change your pythonpython path to:

对于_socket错误,更改pythonpython路径到:

PYTHONPATH=C:\Python27;C:\Python27\Lib;C:\Python27\DLLs

#4


3  

I have added

我已经添加了

if is_win:    
        prefixes.append('C:\PYTHON27')    

to virtualenv.py and it works.

virtualenv。py和它的工作原理。

#5


3  

There is similar problem currently that shows error:

目前有类似的问题显示错误:

AssertionError: Filename C:\Python27\Lib\os.py does not start with any of 
these prefixes: ['C:\\python27']

The difference is in 'C:\python27' being lower case. So the problem manifest itself in that you can not install new virtualenv or make a nested virtualenvs (we do it for testing sometimes). The cause is in the conent of the PYTHONPATH

区别在于“C:\python27”是小写字母。因此,问题出现在您不能安装新的virtualenv或创建嵌套的virtualenv(我们有时会进行测试)。原因就在PYTHONPATH中。

PYTHONPATH=C:\Python27;C:\Python27\Lib

For some reason sys.path in virtualenv.py will return c:\python27, but path to required modules will come form the PYTHONPATH and start with 'C:\Python27\Lib', hence the assertion error.

出于某种原因系统。在virtualenv路径。py将返回c:\python27,但是所需模块的路径将会从PYTHONPATH开始,并以“c:\python27 \Lib”开头,因此会出现断言错误。

Long story short, just unset the PYTHONPATH.

长话短说,只是打开了PYTHONPATH。

#6


2  

Its strange but from the error message

这很奇怪,但从错误的信息。

AssertionError: Filename c:\Python27\Lib\os.py does not start with any of these prefixes: ['C:\\Python27']

It seems, it expects the path-name for the file os.py to start with upper case 'C' and the prefix sanity check is case sensitive.

看起来,它期望文件os的路径名。py从大写字母“C”开始,前缀“完整性检查”是区分大小写的。

As the path to the library is derived from PYTHONPATH and in your case the drive letter is in lower case, it seems logical to change it to upper case to resolve the issue.

由于从PYTHONPATH派生出了通向库的路径,在您的情况下,驱动器字母是小写的,因此将其更改为大写以解决问题似乎是合乎逻辑的。

like

就像

PYTHONPATH=C:\Python27;C:\Python27\Lib

#7


1  

I hate "summary" answers, but as I just went through a very similar issue I thought I would post my solution here as well which draws from several of these answers.

我讨厌“总结”的答案,但当我刚刚经历了一个非常类似的问题时,我想我也会在这里把我的解决方案从几个答案中引出来。

The assert error was caused because I did not have a PYTHONPATH environment variable setup.

断言错误是由于我没有使用PYTHONPATH环境变量设置造成的。

The socket error was caused because I did not include the PythonXX\DLLs folder.

套接字错误是由于我不包括PythonXX\DLLs文件夹造成的。

The full PYTHONPATH environment variable should look follows:

完整的PYTHONPATH环境变量应该是:

PYTHONPATH=C:\Python27;C:\Python27\Lib;C:\Python27\DLLs

#8


1  

This is an error already submitted to the Python development team: https://github.com/pypa/virtualenv/pull/697

这是一个已经提交给Python开发团队的错误:https://github.com/pypa/virtualenv/pull/697。

In the meanwhile why not just change the Python installation folder name to (ptyhon27) to make the assertion work, or if you feel more confortable with that just reinstall python using the alternative location. It works with no issue.

在此期间,为什么不只是将Python安装文件夹名称改为(ptyhon27)来进行断言工作,或者,如果您觉得可以使用替代的位置重新安装Python,您会感到更舒服。它没有问题。

#9


1  

You can try the following (supppose your python is in global path):

您可以尝试以下方法(您的python是在全局路径中):

python -m virtualenv [foldername]

This works for me, Win 10, virtualenv 15.1.0

这对我来说很有效,Win 10, virtualenv 15.1.0。

I get it from this video, it will excute the python lib instead of calling windows exe.

我从这段视频中得到它,它将会把python库去掉,而不是调用windows exe。

#10


0  

I also ran into this problem on Windows 7. My Python27 installation was under C:\Program Files, which obviously contains a space in the path. So, on a separate Windows 7 system that did not contain Python, I did a fresh install of Python27 under C:\Python27 (the default installation path), followed by an install of setuptools (for easy_install).

我在Windows 7上也遇到了这个问题。我的Python27安装在C:\程序文件中,它显然包含了路径中的一个空间。因此,在一个不包含Python的单独的Windows 7系统中,我在C:\Python27(默认的安装路径)下重新安装了Python27,然后安装了setuptools(用于easy_install)。

Afterwards, I was able to install virtualenv CLEANLY without the above assertion error (I used easy_install).

之后,我能够在没有上述断言错误的情况下,轻松地安装virtualenv(我使用easy_install)。

I know that the OP's system is already using the default path, but I thought I would add my experience here as a possible solution for certain specific cases.

我知道OP的系统已经在使用默认路径,但是我想我应该在这里添加我的经验作为某些特定案例的可能解决方案。

#11


0  

This issue is presumably a hangover from other more case-sensitive file systems.

这个问题大概是其他区分大小写的文件系统遗留下来的问题。

Complete solution:

完整的解决方案:

  1. Read the error message from virtualenv. Remember the part where it says "does not start with any of these prefixes: ['C:\\Python27']".

    从virtualenv中读取错误消息。记住它所说的“不以这些前缀开头的部分:['C:\\Python27']”。

  2. Edit PYTHONPATH, or create it if you don't have one (Start+Break, Advanced system settings, Environment Variables). It shouldn't matter if it's a user variable or a system variable, unless you plan to switch user accounts.

    编辑PYTHONPATH,或者创建它,如果您没有一个(启动+中断,高级系统设置,环境变量)。它是一个用户变量还是一个系统变量都不重要,除非您计划切换用户帐户。

  3. Make the case match the error message. BOTH the drive letter AND the folder name must match (presumably intermediate folders as well, if you didn't install to C:\Python27). You can ignore the double backslash, one is fine.

    使情况与错误消息匹配。驱动器号和文件夹名称必须匹配(如果您没有安装到C:\Python27),则必须匹配(可能是中间文件夹)。你可以忽略双反斜杠,一个很好。

The only change I made to fix the bug was as follows. The change should take effect for any new command / terminal sessions (close your open cmd.exe / powershell / etc. windows).

我为修复bug所做的唯一更改是如下所示。更改将对任何新的命令/终端会话生效(关闭您的开放cmd)。exe / powershell / etc. windows)。

  • Old state: PYTHONPATH = C:\PYTHON27;C:\PYTHON27\LIB;C:\PYTHON27\DLLS

    Old state: PYTHONPATH = C:\PYTHON27;C:\PYTHON27\LIB;C:\PYTHON27\ dll。

  • New state: PYTHONPATH = C:\Python27;C:\Python27\LIB;C:\Python27\DLLS

    新状态:PYTHONPATH = C:\Python27;C:\Python27\LIB;C:\Python27\DLLS。

If you have any other items in your PYTHONPATH, you might as well change those too, but it probably won't affect virtualenv's ability to run.

如果您在PYTHONPATH中有任何其他项,您也可以更改它们,但它可能不会影响virtualenv的运行能力。

#12


0  

Change "virtualenv.py" --> change_prefix with:

virtualenv变化”。py”——> change_prefix:

def change_prefix(filename, dst_prefix):
  ...
 prefixes = sorted(prefixes, key=len, reverse=True)
 filename = str(os.path.abspath(filename))[0].lower() + str(os.path.abspath(filename))[1:]
 for src_prefix in prefixes:
    if filename.startswith(src_prefix):
        _, relpath = filename.split(src_prefix, 1)
        if src_prefix != os.sep: # sys.prefix == "/"
            assert relpath[0] == os.sep
            relpath = relpath[1:]
        return join(dst_prefix, relpath)
 assert False, "Filename %s does not start with any of these prefixes: %s" % \
    (filename, prefixes)

  ...

#13


0  

I had the same assertion error from a slightly different cause. The error was does not start with any of these prefixes: ['C:\\python27'] and note the lowercase "p". The actual folder names all use capital-P Python27. All the prefixes in PTYHONPATH were correct. However I had entered the PYTHONHOME variable as C:\python27 and although this was fine for Python, it caused the error in virtualenv.

我从一个稍微不同的原因中得到了相同的断言错误。错误不是从这些前缀开始的:['C:\\python27']和注意小写的“p”。实际的文件夹名称都使用大写- p Python27。PTYHONPATH的所有前缀都是正确的。然而,我输入了PYTHONHOME变量作为C:\python27,尽管这对Python来说很好,但是它在virtualenv中引起了错误。