Moving a Python environment to a new OS

I reinstalled my operating system (moved from Windows XP to Windows 7). I reinstalled Python 2.7.

But I had many packages installed in my old environment. (Django, sciPy, jinja2, matplotlib, numpy, networkx, to name just a view)

I still have my old Python installation lying around the data section, so I wondered if I could just copy the paste of the old Python library folders to the new installation? Or do I need to reinstall every package?

Do packages provide any registry information, system variables, or similar?

Does it depend on the package?

+4
source share
2 answers

The short answer to this question is β€œno,” because packages can execute arbitrary code during installation and do whatever they want, wherever they want on your system.

Just reinstall them all.

+1
source

This is the place where you should be able to compose your project, thereby having special tools for this.

Typically, Python packages do not do things such as working with the registry (unless they are packaged using the MSI installer). Problems may begin with packages containing C-extensions, so the transition to a different version of the OS or from 32 to 64-bit architecture will require recompilation / restoration of these. Thus, it would be much better to reinstall all the packages in the new system, as described below.

Your requirements may vary, but you should definitely choose a way to create your environment. If you do not have and plan to have a large number of projects, you can consider the first approach, as shown below, the second approach is more likely to configure the development environment for different projects or for different versions of the same project.

  • Global environment (your Python installation on your system along with installed packages).

    Here you can use pip . In this case, your project may have a requirements file containing all the necessary packages for your project. Basically, a requirements file is a text file containing package names (in PyPI and their versions).

  • isolated environment . This can be achieved using special tools or a specially organized path.

    Here, where pip can be gracefully combined with virtualenv . This method is highly recommended to many developers (I have to remind you that Python 3.3, which will be released soon, contains virtualenv as part of the standard library). This approach involves creating a virtual shell with its own instance of the Python interpreter and installed packages.

    Another popular tool for achieving an isolated environment is called buildout. It defines the project source and dependencies in one way, so you achieve the same effect as virtualenv. The huge advantage of the construction that it built on the idea of ​​plug-in recipes (pieces of code that implement different common tasks of project deployment), and there are hundreds of stable and reliable recipes on the Internet.

    Both virtualenv and buildout will help you eliminate the headache of installing dependencies and solve the problem with different versions of the same package stored on the same machine.

Choose your fate ...

+2
source

All Articles