26

My scenario is I have two laptops with fresh installation of windows. Now I use both of them for programming.

So, lets suppose I install various python modules/packages in one of the laptop. So is there a way I can clone this complete python setup on my other laptop. The reason for this is my internet connection currently is very slow so I don't want to download the same module or packages twice and than install them again.

I know I can download the modules in zip file, transfer them on other and than run python setup.py install but I am going to use pip to install modules.

Anyways, I was wondering if cloning of python setup is possible.

Cœur
  • 37,241
  • 25
  • 195
  • 267
RanRag
  • 48,359
  • 38
  • 114
  • 167

4 Answers4

35

Here is a completely different suggestion, this is recommended if you want to synchronize the packages between the two PCs and not cloning everything just once.

It only works if you install packages with pip. It does not work for packages which are not installable/installed with pip.

  1. Set up the pip cache to a network storage / USB stick which is accessible from both PCs (see https://stackoverflow.com/a/4806458/851737 for instructions)
  2. Freeze your current package environment from the source PC into a requirements file:

    $ pip freeze > req.txt

  3. Copy the req file to the target PC and install the packages:

    $ pip install -r req.txt

If you put the req.txt under a VCS you can automate and synchronize this process very smoothly.

Community
  • 1
  • 1
schlamar
  • 9,238
  • 3
  • 38
  • 76
  • 2
    even if it doesn't solve this problem, I gave you an upvote for a nice clean solution that other people might find useful! – Hannes Ovrén Jun 14 '12 at 13:52
  • @kigurai Why not? I read his question that he is starting from zero (on both PCs), so he is going to install everything twice and he will download everything just once with this approach. – schlamar Jun 14 '12 at 13:55
  • I suppose I read it as "keeping it in sync without using network connection" and not "clone the environment once". – Hannes Ovrén Jun 14 '12 at 13:57
  • He just says that he has a slow connections and doesn't want to download everything twice and not that he doesn't want to use *any* bandwidth on syncing. – schlamar Jun 14 '12 at 14:00
  • I think I read your solution wrong. I think it actually fit what he wants to do pretty well. – Hannes Ovrén Jun 14 '12 at 14:03
12

If you have the same Python version on both PCs, you can just copy the content of Lib\site-packages and Scripts to the new one. But note that it must be the same minor version (e.g. 2.6 does not work with 2.7).

schlamar
  • 9,238
  • 3
  • 38
  • 76
  • Yes, I have the same python minor version – RanRag Jun 14 '12 at 13:15
  • @RanRag In many cases probably the minor version even does not need to be same. Especially, when the source computer has older version than the target computer. When Python gets updated, the packages usually do not need updating. There may be some rare cases when while copying from source with newer Python the package cannot work in target with a bit older Python. – Roland Pihlakas Jan 05 '18 at 04:51
  • @schlamar , are you saying if you have the Same Version of Python on the Other Computer, you do not have to do a PiP Freeze , when you transfer all the Python Files to the other Computer ? – Calculate Sep 24 '22 at 18:14
  • I wouldn't recommend this anymore. pip is now default. – schlamar Jan 06 '23 at 10:38
5

If you use a virtualenv (http://www.virtualenv.org) you should be able to store that on a USB-stick and carry it with you.

Hannes Ovrén
  • 21,229
  • 9
  • 65
  • 75
  • Nice I didn't knew about that. – RanRag Jun 14 '12 at 13:12
  • 1
    Have you ever tested this? The documentation says about relocatable virtualenv: `Note: this option is somewhat experimental, and there are probably caveats that have not yet been identified. Also this does not currently work on Windows.` – schlamar Jun 14 '12 at 13:16
  • It definitely fails if the drive letter of the stick changes (which could always happen), so this is not a clean solution. – schlamar Jun 14 '12 at 13:26
  • I have relocated virtualenvs on Linux, yes. Has always worked, but then the machines were fairly homogenous. Sad to hear that the support for this on Windows might be a bit shaky. I guess if you instead of keeping it on a USB stick make sure to copy it to disk it might work better. Either way, it is sure worth a try, because it is darned nice when it works :) – Hannes Ovrén Jun 14 '12 at 13:50
1

I was updating Python 2.7.3 --> 2.7.9 on my Windows 7 PC. Normally this would be fine however the new install accidentally went onto the C: instead of where my previous version of python was located, on the D: drive. To get it to work was simply a matter of copying the new install straight over the top of the old. Worked like a charm and all my old modules that I had installed were present.

croc
  • 155
  • 1
  • 6