Renaming a virtualenv folder without breaking it
You need to adjust your install to use relative paths. virtualenv
provides for this with the --relocatable
option. From the docs:
Normally environments are tied to a
specific path. That means that you
cannot move an environment around or
copy it to another computer. You can
fix up an environment to make it
relocatable with the command:$ virtualenv --relocatable ENV
NOTE: ENV is the name of the virtual environment and you must run this from outside the ENV directory.
This will make some of the files
created by setuptools or distribute
use relative paths, and will change
all the scripts to use
activate_this.py instead of using the
location of the Python interpreter to
select the environment.Note: you must run this after you've
installed any packages into the
environment. If you make an
environment relocatable, then install
a new package, you must run virtualenv
--relocatable again.
Can I move a virtualenv?
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.
Renaming a virtualenv folder without breaking it
You need to adjust your install to use relative paths. virtualenv
provides for this with the --relocatable
option. From the docs:
Normally environments are tied to a
specific path. That means that you
cannot move an environment around or
copy it to another computer. You can
fix up an environment to make it
relocatable with the command:$ virtualenv --relocatable ENV
NOTE: ENV is the name of the virtual environment and you must run this from outside the ENV directory.
This will make some of the files
created by setuptools or distribute
use relative paths, and will change
all the scripts to use
activate_this.py instead of using the
location of the Python interpreter to
select the environment.Note: you must run this after you've
installed any packages into the
environment. If you make an
environment relocatable, then install
a new package, you must run virtualenv
--relocatable again.
How can I rename a conda environment?
New answer:
From Conda 4.14 you will be able to use just:
conda rename -n old_name -d new_name
Although, under the hood, conda rename
still uses [1][2] undermentioned combination of conda create
and conda remove
.
Note that the -d
flag is optional. It's for the positional argument, "destination". This should also work:
conda rename -n old_name new_name
Old answer:
You can't.
One workaround is to create clone a new environment and then remove the original one.
First, remember to deactivate your current environment. You can do this with the commands:
deactivate
on Windows orsource deactivate
on macOS/Linux.
Then:
conda create --name new_name --clone old_name
conda remove --name old_name --all # or its alias: `conda env remove --name old_name`
Notice there are several drawbacks of this method:
- It redownloads packages (you can use
--offline
flag to disable it) - Time consumed on copying environment's files
- Temporary double disk usage
There is an open issue requesting this feature.
Poetry: How to keep using the old virtual environment when changing the name of the project root folder?
One option is to enable the virtualenvs.in-project
option, e.g. by running
poetry config virtualenvs.in-project true
If set to
true
, the virtualenv wil [sic] be created and expected in a folder named.venv
within the root directory of the project.
This will cause Poetry to create new environments in $project_root/.venv/
. If you rename the project directory the environment should continue to work.
Renaming a virtualenv folder without breaking it
You need to adjust your install to use relative paths. virtualenv
provides for this with the --relocatable
option. From the docs:
Normally environments are tied to a
specific path. That means that you
cannot move an environment around or
copy it to another computer. You can
fix up an environment to make it
relocatable with the command:$ virtualenv --relocatable ENV
NOTE: ENV is the name of the virtual environment and you must run this from outside the ENV directory.
This will make some of the files
created by setuptools or distribute
use relative paths, and will change
all the scripts to use
activate_this.py instead of using the
location of the Python interpreter to
select the environment.Note: you must run this after you've
installed any packages into the
environment. If you make an
environment relocatable, then install
a new package, you must run virtualenv
--relocatable again.
Related Topics
Python VS. Ruby for Metaprogramming
Which of These Scripting Languages Is More Appropriate for Pen-Testing
What Is the Performance Impact of Non-Unique Indexes in Pandas
What's the Best Way to Return Multiple Values from a Function
Programmatically Extract Data from an Excel Spreadsheet
What Programming Language Features Are Well Suited for Developing a Live Coding Framework
Swift Playground Error: Module 'Python' Has No Member Named 'Import'
Swift If Or/And Statement Like Python
How to Import a Python Class That Is in a Directory Above
How to Print Variable and String on Same Line in Python
What Is the Good Python3 Equivalent for Auto Tuple Unpacking in Lambda
Python Image Library Fails with Message "Decoder Jpeg Not Available" - Pil
How to Map Numeric Data into Categories/Bins in Pandas Dataframe
What Is a "Good" Palette for Divergent Colors in R? (Or: Can Viridis and Magma Be Combined Together)