Question

Using virtualenvwrapper, I installed Django for one virtualenv. Now I can't reach it outside that environment. I want to be able to start new Django projects both outside any virtualenv, and inside new virtualenvs.

Do I need to reinstall Django or can I somehow import the installation from my first virtualenv?

Était-ce utile?

La solution

I would recommend just starting from scratch with a new virtualenv. That is the reason that they are built: one virtualenv can house a project that uses one version of Django, but another project can use a separate version of Django (perhaps an older version because an app you're using doesn't yet work with the newer version).

If you are attempting to completely recreate the same environment (probably because you want to run the project in another spot), you can use the pip freeze in alexcxe's answer. This will install everything again from scratch, attempting to install the exact same version. You may or may not want to do this, for the reasons I mentioned in the first paragraph.

This is the entire point of virtual environments. I have 20 different projects on my computer, each with their own virtualenv. It's fairly common to work in this manner.

Autres conseils

The easiest way to go is to freeze your requirements into requirements.txt and then install them in the new virtualenv:

pip freeze > requirements.txt
pip install -r requirements.txt

Another option is to make your virtual environment relocateable and copy each time you need a new one. This is somewhat harder to do, see:

FYI, virtualenvwrapper has cpvirtualenv command, but you should use it with caution:

Copying virtual environments is not well supported. Each virtualenv has path information hard-coded into it, and there may be cases where the copy code does not know to update a particular file. Use with caution.

You can use the add2virtualenv command of virtualenvwrapper.

If you have good internet connection, installing django (or else) for each new Virtualenv instance may not be the problem. But should you want to copy an existing virtualenv packages to the new one, you can simply do the following (picture attached), which simply create a blank virtualenv and copy all site-packages to the new one

Picture above is about moving virtualenv to another directory, which cause it to break. But the essence with creating a new virtualenv with existing packages is the same

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top