I am working on a Python project on both my work computer and my home computer. GitHub has made the experience pretty seamless.
But I'm having a problem with the pyvenv.cfg
file in my venv
folder. Because my Python SDK has a different file path on my work computer compared to my home computer, I have to manually go into pyvenv.cfg
to change the home = C:\Users\myName\...
filepath each time I pull the updated version of my project from my other computer, or else the interpreter doesn't work.
Does anyone know a solution to this problem?
As confirmed in the comments, you've added the virtual environment folder to your project and included it in the files that you put on GitHub.
That's generally a bad idea, since it defeats part of the purpose of having a virtual environment in the first place. Your virtual environment will contain packages specific to the platform and configuration of the machine it is on - you could be developing on Linux on one machine and Windows on another and you'd have bigger problems than just one line in a configuration file.
What you should do:
pip
, you can run pip freeze > requirements.txt
to create a requirements.txt
folder which you can then use on the other system with pip install -r requirements.txt
to recreate the exact same virtual environment.All you have to do is keep that requirements.txt
up to date and update the virtual environments on either computer whenever it changes, instead of pulling it through GitHub.
In more detail, a simple example (for Windows, very similar for Linux):
C:\projects\my_project
python -m venv C:\projects\venv\my_project
C:\projects\venv\my_project\Scripts\activate.bat
pip install numpy
C:\projects\my_project
, called requirements.txt
with pip freeze > requirements.txt
git clone https://github.com/my_project D:\workwork\projects\my_project
python -m venv D:\workwork\venv\my_project
D:\workwork\venv\my_project\Scripts\activate.bat
pip install -r D:\workwork\projects\my_project\requirements.txt
Since you say you're using PyCharm, it's a lot easier still, just make sure that the environment created by PyCharm sits outside your project folder. I like to keep all my virtual environments in one folder, with venv-names that match the project names.
You can still create a requirements.txt
in your project and when you pull the project to another PC with PyCharm, just do the same: create a venv outside the project folder. PyCharm will recognise that it's missing packages from the requirements file and offer to install them for you.