Python move venv to another system

Copy venv from one folder to another and still be able to use it?

But when I moved that virtualenv to a different system (python3 installed) and ran my application with the absolute path of my virtualenv python (c:/. /myenv/Scripts/python.exe main.py) then it threw the errors that packages are not installed, I activated the virtualenv and used pip freeze and there were no packages were installed. My Question is how to use the packages that are inside ‘site-packages’ even after moving the virtualenv to different system in Python 3.

Copy venv from one folder to another and still be able to use it?

If you have ever copied the python folder from one location to another and faced problem using it, this article will help you understand how you can solve this problem.

Let us first create a folder, named example and then create a virtual environment and install flask using pip

$ mkdir example $ cd example $ python -m venv venv $ source venv/bin/activate $ pip install Flask 

Now you have a virtual env with flask installed.

After doing this python sets an environment variable VIRTUAL_ENV , let us check its value.

$ echo $VIRTUAL_ENV /home/username/example/venv 

We will now move this venv folder to some other folder.

$ mkdir example2 $ mv venv/ example2/ $ cd example2 $ source venv/bin/activate 

Now let us check the value of VIRTUAL_ENV variable

$ echo $VIRTUAL_ENV /home/username/example/venv 

Wow, this is strange. I have moved the folder but still the value of VIRTUAL_ENV variable is the same?
This is because when you create the virtual environment, the location is hardcoded based on current directory.
You can check this inside activate file we have previously used to activate the virtual environment.
You will find something like VIRTUAL_ENV=’/home/username/example/venv’.

The solution for using the virtual environment at the new location is simple. Just change this path in all program inside venv/bin directory to the new path 🙂
Please don’t do it manually.
Use tools like sed on unix or similar tools for the same.

$ old_path='/home/username/example/venv' $ new_path='/home/username/example/example2/venv' $ cd venv/bin/ $ sed -i "s|$old_path|$new_path|g" * 

The last command is replace in-place the value of old_path with new_path. * signifies all files in current directory(not exactly, but for this example consider it). Make sure you run this command while present in venv/bin folder.

After doing this reactivate the virtual env.

How to copy modules from one virtualenv to another, Edit: this doesn’t answer the question «How to copy modules from one virtualenv to another» but I’m pretty sure the result is in many cases the desired one, namely the creation of a new venv based on a previously created one which includes (all of) the previously installed modules.

Читайте также:  Python checking if file is empty

How to copy modules from one virtualenv to another

Is it possibe to copy python modules from one virtualenv to another.If so how is this done?

As long as you’re moving them from one virtualenv to another on the same machine, you could easily just do:

$ cp -r [env1]/lib/pythonX.X/site-packages/* [env2]/lib/pythonX.X/site-packages/ 

However, if the environments are on different machines or utilizing different versions of python or some other major difference, it’s probably not a good idea. In general it’s much safer to generate a requirements.txt , and then use that to load up all the same modules in the other environment. You can create the file manually if you like, but it’s easier to just use pip .

$ pip freeze -E [env1] > requirements.txt 

Or, if your virtualenv is activated already, you can simply do:

$ pip freeze > requirements.txt 

Then, in your other environment, you can do:

$ pip install -E [env2] -r /path/to/requirements.txt 

I am working on a 64bit machine with Ubuntu-14.04-64. I compiled and installed python-3.4.3 to /opt/python3.4/ and created a vitualenv based on this python.

mkvirtualenv -p /opt/python3.4/bin/python venv1 
sudo apt-get install virtualenvwrapper 

With the venv installed and working with PyQt5 successfully (the hard bit) plus numpy, scipy, ipython etc. I installed virtualenv-clone:

workon myvenv pip install virtual-clone deactivate 
virtualenv-clone venv1 venv2 

PyQt5 works this way. The command-line prompt still names venv1 as active but within ~/.virtualenv/venv2

shows 3 entries within the three files activate , activate.csh , and activate.fish

if [ "x(myvenv1) " != x ] ; then PS1="(myvenv1) $PS1" else 
if ("venv1" != "") then set env_name = "venv1" else 
if test -n "(venv1) " printf "%s%s%s" "(venv1) " (set_color normal) (_old_fish_prompt) return end 
. printf "%s%s%s" "(venv2) " (set_color normal) (_old_fish_prompt) . 

Now when you source ~/.virtualenv/venv2/bin/activate or workon venv2 the command prompt will correctly display your environment (the cloned copy of venv1).

Edit: this doesn’t answer the question «How to copy modules from one virtualenv to another» but I’m pretty sure the result is in many cases the desired one, namely the creation of a new venv based on a previously created one which includes (all of) the previously installed modules.

Usually you are able to copy the .egg-info from the lib/site-packages folder of the virtualenv to the lib/site-packages of the other environment.

seems like we can’t just copy one virtualenv as another one. even you chnage the $VIRTUAL_ENV in the activate file, it still act as in origin virtualenv and pip will install all the packages to origin site-packages/

How to clone a venv virtual environment?, However it is good practice to create a requirements.txt file in your venvs anyway. To copy your venv to a new location. Activate your original venv. Get your requirements by doing the following in your virtual environment. pip freeze > requirements.txt Deactivate your venv. Then you would want to create a new …

Move the virtualenvs to another host folder

By error, I forgot to specify the WORKON_HOME variable before creating my virtual environments, and they were created in /root/.virtualenvs directory. They worked fine, and I did some testing by activating certain environment and then doing (env)$ pip freeze to see what specific modules are installed there.

Читайте также:  Javafx exception in thread javafx application thread java lang nullpointerexception

So, whe I discovered the workon home path error, I needed to change the host directory to /usr/local/pythonenv . I created it and moved all the contents of /root/.virtualenvs directory to /usr/local/pythonenv , and changed the value of WORKON_HOME variable. Now, activating an environment using workon command seems to work fine (ie, the promt changes to (env)$ ), however if I do (env)$ pip freeze , I get way longer list of modules than before and those do not include the ones installed in that particular env before the move.

I guess that just moving the files and specifying another dir for WORKON_HOME variable was not enough. Is there some config where I should specify the new location of the host directory, or some config files for the particular environment?

Virtualenvs are not by default relocatable. You can use virtualenv —relocatable to turn an existing virtualenv into a relocatable one, and see if that works. But that option is experimental and not really recommended for use.

The most reliable way is to create new virtualenvs. Use pip freeze -l > requirements.txt in the old ones to get a list of installed packages, create the new virtualenv, and use pip install -r requirements.txt to install the packages in the new one.

I used the virtualenv —relocatable feature. It seemed to work but then I found a different python version installed:

$ . VirtualEnvs/moslog/bin/activate (moslog)$ ~/VirtualEnvs/moslog/bin/mosloganalisys.py python: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory 

Remember to recreate the same virtualenv tree on the destination host.

Python — How to copy virtualenv to another machine, Ideally, you don’t copy virtualenv to a production machine. Instead, Create a PEX file & ask admins to install python3 on production host. Virtualenv is a concept for developers. As developers are working on different projects and different projects use different version of libraries. Virtualenv provides solution to …

How to move Python virtualenv to different system (computer) and use packages present in Site-packages

I am making a python 3 application (flask based) and for that I created a virtualenv in my development system, installed all packages via pip and my app worked fine.

But when I moved that virtualenv to a different system (python3 installed) and ran my application with the absolute path of my virtualenv python (c:/. /myenv/Scripts/python.exe main.py) then it threw the errors that packages are not installed, I activated the virtualenv and used pip freeze and there were no packages were installed.

But under virtualenv there is ‘Site-Packages’ (myenv -> lib -> site-packages) , all my installed packages were persent there.

My Question is how to use the packages that are inside ‘site-packages’ even after moving the virtualenv to different system in Python 3.

Moving a virtualenv from a computer to another, and even on the same computer from a location to another is a bad idea , and this is why :

  • Since a lot of the binaries and libs are symlinks, and linked to your old system binaries and libs, it won’t work on other machines.
  • Since many of bin/ scripts in your virtualenv depends on the virtualenv path on the system , it won’t work if you moved the virtualenv to another location (even on same system either .)
 pip freeze > requirements.txt 
 pip install -r requirements.txt 

Finally in your case if you really didn’t generated a requirements.txt file, and need to use the old site-packages , there is a dirty workaround which i tried once on a gnu/linux machine and somehow worked but am not 100% sure if it will work properly so if you want give it a try.

  • copy the site-packages in your-old-virtualenv/lib/python/ somewhere in your new computer , Desktop for example
  • Delete the old virtualenv, and create a new virtualenv
  • Replace the site-packages in the new virtualenv in new-virtualenv/lib/python with the old site-packages
  • Delete __pycache__ folder in the newly copied site-packages
  • Activate the new virtualenv and test if everything is working .
Читайте также:  Create wp config php manually

Note that you should use the same python version either 2 or 3 , don’t expect a virtualenv that depends on python2 to run properly with python3

Maybe you can consider using pipenv to control the virtualenvs on different computer or environment.

You Must not copy & paste venv, even in the same system.
If you install new package in venv-copied , then it would installed in venv-original .
Becaus settings are bound to specific directory.

Where do I put my python files in the venv folder?, (Probably a noob question, but I didn’t find a solution after googling for 20 minutes.) I created a new pure Python project with PyCharm which yielded the following folder structure. myproject └── venv ├── bin │ ├── activate │ ├── activate.csh │ ├── activate.fish │ ├── easy_install │ ├── easy_install-3.5 │ …

Источник

Перенести виртуальное окружение python на другой компьютер debian

Ситуация: мне надо тестить некотороые темы в python на работе где у меня нет админских прав, но надо поставить некоторые библиотеки.

Система на работе debian8, дома debian10, но поставлю любую, если это принципиально.
Портабл питон от pippy не подходит по версии питона.

Я решил попробовать создать виртуальное окружение на домашней машине и запустить его потом на работе.
Поставил питон 3.4 создал виртуалку. На работе отредактировал в виртуалке файлы: pyvenv.cfg — параметр home , и в файлах bin/activate и bin/activate.csh и bin/activate.fish — параметры VIRTUAL_ENV — на текущие.

В итоге виртуалка внешне активируется и деактивируется, ошибок не пишет, но which python — пишет /usr/bin/python а не в path/to/my/env/bin/python .

И у меня вопрос надо ли сделать что-то ещё, или это в принципе не возможно?

Виртуальное окружение python
Подскажите как сделать проект с виртуальным окружением, чтобы проект можно было запустить на другой.

Как создать виртуальное окружение с другой версией Пайтона?
В системе по умолчанию 3.8.2, а нужны виртуальные окружения для версий 3.6 и 3.7 ещё. Ещё.

Установка PyQT5 в виртуальное окружение (Debian)
Всем доброго времени суток! Создал виртуальное окружение с помощью virtualenv с Python3.4 и.

Не активируется виртуальное окружение python windows 7 (venv, env, pip)
Здравствуйте! столкнулся с такой проблемой: не активируется виртуально окружение, которое ранее.

Источник

Оцените статью