How to rename a virtualenv in Python?

前端 未结 4 1492
轻奢々
轻奢々 2020-12-07 10:48

I misspelled the name of the virtualenv while initializing it using:

$ virtualenv vnev

I actually intended to create the envir

4条回答
  •  醉梦人生
    2020-12-07 11:31

    By default virtualenv does not support the renaming of environments. It is safer to just delete the virtualenv directory and create a new one with the correct name. You can do this by:

    1. Activate your virtualenv: source vnev/bin/activate
    2. Create a requirements.txt of currently installed packages: pip freeze > requirements.txt
    3. Delete the misspelled virtualenv: rm -r vnev/
    4. Create a new virtualenv with correct name: virtualenv venv
    5. Activate new virtualenv: source venv/bin/activate
    6. Install packages from requirements.txt: pip install -r requirements.txt

    If recreating is not an option there are 3rd party tools like virtualenv-mv that might be helpful.

    Alternatively you can use virtualenvwrapper which provides the cpvirtualenv command to copy or rename virtualenvs.

提交回复
热议问题