Copy complete virtualenv to another pc

后端 未结 4 942
礼貌的吻别
礼貌的吻别 2020-12-29 07:45

I have a virtualenv located at /home/user/virtualenvs/Environment. Now I need this environment at another PC. So I installed virtualenv-clone

相关标签:
4条回答
  • 2020-12-29 08:20

    Usually I use virtualenv to create a new environment, then I go to the environment where I want to copy from, copy all the folders and paste it into the environment folder I just created, but most importantly when asking if you want to replace the Destination files, choose to skip these files. This way you keep your settings. At least for me, this has worked very well. I hope it works for you too.

    0 讨论(0)
  • 2020-12-29 08:31

    Do the following steps on the source machine:

    1. workon [environment_name]
    2. pip freeze > requirements.txt
    3. copy requirements.txt to other PC

    On the other PC:

    1. create a virtual environment using mkvirtualenv [environment_name]
    2. workon [environment_name]
    3. pip install -r requirements.txt

    You should be done.

    Other Resources:

    • How to Copy/Clone a Virtual Environment from Server to Local Machine
    0 讨论(0)
  • 2020-12-29 08:36

    I think what occurs is that you just copy the symbolic links in the source file to the target machine as binary files(no longer links). You should copy it using rsync -l to copy to keep those links.

    0 讨论(0)
  • 2020-12-29 08:44

    I share my experience.

    Suppose another PC does not install Python
    Python version: 3.7.3 
    Platform: Platform: Windows 10, 7 (64bit)
    

    The following is working for me.

    Step:

    1. download Windows embeddable zip file
    2. download get-pip.py (because the embeddable zip file does not provide pip)
    3. [Optional] install tkinter, see this article: Python embeddable zip: install Tkinter
    4. Choose a packaging method (I use NSIS: https://nsis.sourceforge.io/Download)

    folder artictures:

    - main.nsi
    - InstallData
        - contains: Step1 & Step2
    - YourSitePackages  # I mean that packages you do not intend to publish to PyPI.
        - LICENSE
        - MANIFEST.in
        - README.rst
        - ...
        - requirements.txt
        - setup.py
    

    The abbreviated content about main.nsi is as follows:

    !define InstallDirPath "$PROGRAMFILES\ENV_PYTHON37_X64"
    !define EnvScriptsPath "${InstallDirPath}\Scripts"
    ...
    
    CreateDirectory "${InstallDirPath}"  # Make sure the directory exists before the writing of Uninstaller. Otherwise, it may not write correctly!
    SetOutPath "${InstallDirPath}"
    SetOverwrite on
    File /nonfatal /r "InstallData\*.*"
    
    SetOutPath "${InstallDirPath}\temp"
    SetOverwrite on
    File /nonfatal /r "YourSitePackages\*.*"
    nsExec::ExecToStack '"${InstallDirPath}\python.exe" "${InstallDirPath}\get-pip.py"'  # install pip
    nsExec::ExecToStack '"${InstallDirPath}\Scripts\pip.exe" install "${InstallDirPath}\temp\."'  # install you library. same as: `pip install .`
    RMDir /r "${InstallDirPath}\temp"  # remove source folder.
    ...
    
    /*
    Push ${EnvScriptsPath}  # Be Careful about the length of the HKLM.Path. it is recommended to write it to the HKCU.Path, it is difficult for the user path to exceed the length limit
    Call AddToPath  # https://nsis.sourceforge.io/Path_Manipulation
    */
    
    

    hope someone will benefit from this.

    0 讨论(0)
提交回复
热议问题