0

I would like to easily export one Python project from one PC to other. When I created the project, I used a virtual environment in order to avoid problems with different package versions.

What I did was to just copy the project folder and paste it in the destination PC. Once I opened the project with Pycharm, I activated the virtual environment with project_path/venv/Scripts/activate, but when I tried to execute any Script, it said it didn´t find the modules.

Which is the workflow I should follow in order to create projects and be able to run them from multiple PC-s without needing to install all the dependencies?

binflo13
  • 1
  • 3
  • What are the versions of python? These should be at least the same. – BlueSheepToken Jun 07 '19 at 11:11
  • Possible duplicate of [What parts of a virtualenv need to be changed to relocate it?](https://stackoverflow.com/questions/6820109/what-parts-of-a-virtualenv-need-to-be-changed-to-relocate-it) – phd Jun 07 '19 at 11:18
  • https://stackoverflow.com/search?q=%5Bvirtualenv%5D+relocate – phd Jun 07 '19 at 11:18
  • Virtualenvs aren't relocatable. Freeze the list of packages at the source venv, create a new destination venv and reinstall the packages. – phd Jun 07 '19 at 11:19
  • I use Python 3.7 on Windows, but I have Python 3.6 also installed. – binflo13 Jun 07 '19 at 11:50

2 Answers2

4

Since you did not specify your Python version I will provide a solution working for both Python 2.x and 3.x.

My suggestion is to create a requirements.txt file containing all your requirements.

This file can be easily prepared using the output from the command:
pip freeze

Then you can paste the output in your requirements.txt file and when you are going to install your Python code on another PC you can simply:
pip install -r requirements.txt

To install your requirements again.

Depending on your project it could be possible, for example, to create a single EXE file (if you are using Windows machines) but more detailed is needed if this is the case.

In case you are using Python 3 the method that is at the moment arguably more popular in the Python community is Pipenv.

Here's its relevant documentation.

And here you can read a simple example of a workflow.

Dodge
  • 3,219
  • 3
  • 19
  • 38
Pitto
  • 8,229
  • 3
  • 42
  • 51
  • I use Python 3.7 on Windows. – binflo13 Jun 07 '19 at 11:51
  • Hi @binflo13 I have updated my answer with details specifically Python 3 related. Please upvote it and / or choose it as final answer if it was useful for you. – Pitto Jun 12 '19 at 14:53
1

if you are using python3 then use pipenv. It will automatically create Pipfile and Pipfile.lock. That will insure reinstalling dependencies on different machine will have the same packages.

basic and helpful commands:

  • pipenv shell # activate virutalenv
  • pipenv install # will install dependencies in Pipfile
  • pipenv install requests # will install requests lib. and will auto update Pipfile and Pipfile.lock