简体   繁体   中英

Moving a Python environment over to a new OS install

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

But i had a lot of 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 on a data partition, so i wondered if i can just copy-paste the old Python library folders onto the new installation? Or do i need to reinstall every package?

Do the packages keep any information in registry, system variables or similar?

Does it depend on the package?

That's the point where you must be able to layout your project, thus having special tools for that.

Normally, Python packages do not do such wierd things as dealing with registry (unless they are packaged via MSI installer). The problems may start with packages that contain C extensions, so moving to another version of OS or from 32 to 64-bit architecture will require recompiling/rebuilding of those. So, it would be much better to reinstall all packages to new system as written below.

Your demands may vary, but you definitely must choose the way of building your environment. If you don't have and plan to have a large variety of projects you may consider the first approach as follows below, the second approach is more likely for setting up development environment for different projects or for different versions of the same project.

  1. Global environment (your Python installation in your system along with installed packages).

    Here you can consider using pip . In this case your project can have requirements file containing all needed packages for your project. Basically, requirements file is a text file containing package names (on PyPI and their versions).

  2. Isolated environment . It can be achieved using special tools or specially organized path.

    Here where pip can be gracefully combined with virtualenv . This way is highly recommended by a lot of developers (I must remind that Python 3.3 that will soon be released contains virtualenv as a part of standard library). This approach assumes creating virtual shell with its own instance of Python interpreter and installed packages.

    Another popular tool for achieving isolated environment is called buildout. It lays out your project source and dependencies in one path so you achieve the same effect as virtualenv creates. The great advantage of buildout that it's built upon an idea of pluggable recipes (pieces of code implementing different common project deployment tasks) and there are hundreds of stable and reliable recipes over Internet.

    Both virtualenv and buildout help you to remove head-ache when installing dependencies and solve the problem of different versions of the same package kept on a single machine.

Choose your destiny...

The short answer to this question is "no", since packages can execute arbitrary code on installation and do whatever the heck they want wherever they want on your system.

Just reinstall all of them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM