我可以移动一个 virtualenv 吗? [英] Can I move a virtualenv?

查看:46
本文介绍了我可以移动一个 virtualenv 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题不是重复的.

它不仅涉及重命名一个虚拟环境,还涉及实际移动到一个不同的目录,可能包括一个不同的用户目录.

这与仅仅重命名虚拟环境不同,尤其是对于不熟悉 virtualenvs 的人.

如果我创建了一个 virtualenv,并将它移动到另一个文件夹,它还能工作吗?

$ virtualenv -p/usr/bin/python3/home/me/Env/my-python-venv$ 源环境/my-python-venv/bin/activate(my-python-venv) $

...那天晚些时候,虚拟环境移动了...

(my-python-venv) $ 停用$ mkdir -p/home/me/PeskyPartyPEnvs$ mv/home/me/Env/my-python-venv/home/me/PeskyPartyPEnvs/

问题:

这行得通吗?

$ source/home/me/PeskyPartyPEnvs/my-python-venv/bin/activate(my-python-venv) $/home/me/PeskyPartyPEnvs/my-python-venv/bin/pip3 安装 foaas

我的意思是这不是一个关于尝试这个是否明智的问题(当然,除非这种智慧很幽默),更多的是关于它是否可能.我真的很想知道在 Python 3 中是否可以做到,或者我是否只需要

好吧,你不能.

This question is not a duplicate.

It pertains not just to renaming a virtual environment, but to actually moving it to a different directory, including, potentially, a different user's directory.

This is not the same as merely renaming a virtual environment, especially to people unfamiliar with virtualenvs.

If I create a virtualenv, and I move it to a different folder, will it still work?

$ virtualenv -p /usr/bin/python3 /home/me/Env/my-python-venv
$ source Env/my-python-venv/bin/activate
(my-python-venv) $ 

...later that day, the virtual environment MOVED...

(my-python-venv) $ deactivate
$ mkdir -p /home/me/PeskyPartyPEnvs
$ mv /home/me/Env/my-python-venv /home/me/PeskyPartyPEnvs/

Question:

Will this work?

$ source /home/me/PeskyPartyPEnvs/my-python-venv/bin/activate
(my-python-venv) $ /home/me/PeskyPartyPEnvs/my-python-venv/bin/pip3 install foaas

I mean this as less of a question about the wisdom of trying this (unless that wisdom is humorous, of course), and more about whether it's possible. I really want to know whether it's possible to do in Python 3, or whether I just have to suck it up and clone it.

Can I just mv a virtualenv like that without sadness? I do want to avoid sadness.

解决方案

BUT ALAS:

No, you can't simply mv. There are workarounds, but it might be easier to reinstall.

(my-python-venv)$ /home/me/PeskyPartyPEnvs/pip3 install foaas
zsh: /home/me/PeskyPartyPEnvs/pip3: bad interpreter: /home/me/Env/my-python-venv/bin/python3: no such file or directory
(my-python-venv)$ deactivate
$ 

... presses enter a lot in frustration, and the following works

$
$
$ pip3 search foaas

Except it is not from my-python-venv, ergo sadness.

Want to mv your virtualenv and use it, otherwise unmodified?

Short Answer:

Well, ya can't.

这篇关于我可以移动一个 virtualenv 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆