使用不同的 python 安装 virtualenv 时断言错误

发布于 2024-10-17 04:38:16 字数 915 浏览 6 评论 0原文

我的服务器有Python2.5,我想跳转到最新的Python(在我的例子中是2.7.x)。我从源代码编译了 python,下载了最新的 virtualenv (1.5.1)。

现在基本上我想做的是:

./packages/virtualenv/virtualenv.py --python=packages/Python-2.7/python env/

键入:

./packages/virtualenv/virtualenv.py

提供:

1.5.1

键入时:

packages/Python-2.7/python

提供:

Python 2.7 (r27:82500, Nov 21 2010, 23:19:15) 
[GCC 4.3.2] on linux2
(cut help mesage)
>>>

但是运行 virutalenv 会导致:

AssertionError: Filename /packages/Python-2.7/Lib/os.py 不以任何这些前缀开头:['/ usr/local']

无论这意味着什么,无论我是什么,或者我没有做错。

聚苯乙烯 在构建 env + python 时,我基于问题: 如何使用自定义构建的 Python 创建 virtualenv 环境来解决此问题?

My server has Python2.5 I wanna be jump to newest Python (2.7.x in my case). I compiled python from source, I downloaded newest virtualenv (1.5.1).

Now basically what im trying to do:

./packages/virtualenv/virtualenv.py --python=packages/Python-2.7/python env/

Typing:

./packages/virtualenv/virtualenv.py

Provides:

1.5.1

While Typing:

packages/Python-2.7/python

Provides:

Python 2.7 (r27:82500, Nov 21 2010, 23:19:15) 
[GCC 4.3.2] on linux2
(cut help mesage)
>>>

However runing virutalenv results in:

AssertionError: Filename /packages/Python-2.7/Lib/os.py does not start with any of these prefixes: ['/usr/local']

Whatever it means and whatever I am or I am not doing wrong.

P.S.
While building env + python I based at question: How do I work around this problem creating a virtualenv environment with a custom-build Python?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

柒夜笙歌凉 2024-10-24 04:38:16

阅读并弄乱 这个

我发现这个错误可能与运行 python 的 ./configure 时缺少 --prefix 有关。所以我运行了 ./configure --prefix=/Path/To/Where/I/Want/Python/After/Compilation/ (在我的例子中 $HOME/packages/Python- 2.7),然后我输入了 make,然后 make install (不使用 sudo - 所以 python 被安全地放入其中我告诉它是当前用户而不是 root )。之后 virtualenv 启动并没有因 AssertionError 崩溃,一切都顺利进行。

希望作者回答的这个问题最终能帮助别人。 :)

After reading and messing with this.

I found that this error might be related with lack of --prefix while runing ./configure for python. So I've run ./configure --prefix=/Path/To/Where/I/Want/Python/After/Compilation/ (in my case $HOME/packages/Python-2.7), then I've typed make, then make install (without using sudo - so python was safely put into where I told it to be as current user not root). After that virtualenv initiation did not crash with AssertionError and everything worked like a charm.

Hope that this question answered by author will eventually help someone. :)

伏妖词 2024-10-24 04:38:16

我没有足够的代表将其添加为评论,并且这个问题已有 3 年历史,但这可能对某人有用。在 Windows 中,您必须找到 python.exe 的路径,但似乎在 Linux/OS X 中您只需路径到该文件夹​​。示例:

Windows:

virtualenv -p <PATH TO PYTHON.EXE> venv

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

I don't have enough rep to add this as a comment and this question is 3 years old, but this might be useful to someone. In Windows, you have to path out to python.exe, but it seems that in Linux/OS X you just path to the folder. Example:

Windows:

virtualenv -p <PATH TO PYTHON.EXE> venv

Creates a virtual environment in subfolder "venv" in current directory.

在巴黎塔顶看东京樱花 2024-10-24 04:38:16

我没有足够的代表来添加评论。 迈克的回答拯救了我。我正在使用窗户。

我收到错误:

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

我必须运行它 -

virtualenv -p C:\Python35\python.exe venv

还需要从以管理员身份打开的 cmd 运行它。否则会收到错误

PermissionError: [WinError 5] Access is denied

有人有足够的代表发表评论,请将其添加到 Mike 的 答案中作为评论。然后我会清除我的。

I don't have enough rep to add comment. Mike's answer save my day. I'm using windows.

I was getting the error :

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

I had to run this-

virtualenv -p C:\Python35\python.exe venv

also need to run this from a cmd opened as Administrator. Otherwise getting the error

PermissionError: [WinError 5] Access is denied

Someone with enough reps to comment please add this to Mike's answer as a comment. I'll then clear mine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文