Python Forum
Windows, Linux and virtual environments
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Windows, Linux and virtual environments
#1
This is more thinking out loud than a question.

Say I'm developing a python app on a Windows machine. I'm using a virtual environment on the Windows machine to debug my code. The target for the app is a Linux machine. When I deploy my app, the virtual environment won't be any good.

Would it make more sense to develop without the virtual environment?

Would it work if I created one virtual environment on the Windows machine and one on the Linux machine with the same name? I would just manually make sure that I install the same modules on both? There would be a danger of deploying the Window virtual environment into the Linux virtual environment by mistake.

Then you can throw MacOS into the mix, so now you would need to maintain three different virtual environments for the app.

This seems very messy. I feel like I'm overlooking something. Is my understanding correct, or is there a way to avoid this?
Reply
#2
I don't like working without a virtual environment. There are many disadvantages, not the least of which is working projects that require different versions of python. A better option is to network all of the computers, and use version control, git, sccs or other. You can keep a requirements file in the version control, which will make setting up a new virtual environment a snap, for example: pip install -r requirements.txt
menator01 and Gribouillis like this post
Reply
#3
Look into uv it's the new Python package and project manager.
It's make cross platform stuff easier,and new that feature is that it also will download Python version needed if not have it on OS.
uv lock and uv sync make easy it to make same environment on all OS.
It i do quick run on Windows
G:\div_code
λ uv --version
uv 0.6.5 (bcbcd0a1e 2025-03-06)

G:\div_code
λ uv init my_app
Initialized project `my-app` at `G:\div_code\my_app`

G:\div_code
λ cd my_app\

G:\div_code\my_app (main)
λ ls
main.py  pyproject.toml  README.md

G:\div_code\my_app (main)
λ uv venv
Using CPython 3.13.1
Creating virtual environment at: .venv
Activate with: .venv\Scripts\activate

G:\div_code\my_app (main)
λ .venv\Scripts\activate

G:\div_code\my_app (main)
(my_app) λ uv lock
Resolved 7 packages in 851ms

G:\div_code\my_app (main)
(my_app) λ uv sync
Resolved 7 packages in 2ms
Prepared 6 packages in 18.70s
░░░░░░░░░░░░░░░░░░░░ [0/6] Installing wheels...
Installed 6 packages in 3.89s
 + certifi==2025.1.31
 + charset-normalizer==3.4.1
 + idna==3.10
 + numpy==2.2.0
 + requests==2.32.3
 + urllib3==2.3.0
How pyproject.toml look.
[project]
name = "my-app"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.13.1"
dependencies = [
    "requests==2.32.3",
    "numpy==2.2.0",
]
Now on Linux. can use the two files pyproject.toml and uv.lock to create same environment on Linux.
tom@tom-VirtualBox:~$ uv init new_app
Initialized project `new-app` at `/home/tom/new_app`
tom@tom-VirtualBox:~$ cd new_app/
tom@tom-VirtualBox:~/new_app$ ls
main.py  pyproject.toml  README.md

tom@tom-VirtualBox:~/new_app$ uv sync
Using CPython 3.13.1
Creating virtual environment at: .venv
Resolved 7 packages in 1ms
Installed 6 packages in 113ms
 + certifi==2025.1.31
 + charset-normalizer==3.4.1
 + idna==3.10
 + numpy==2.2.0
 + requests==2.32.3
 + urllib3==2.3.0

tom@tom-VirtualBox:~/new_app$ uv venv
Using CPython 3.13.1
Creating virtual environment at: .venv
Activate with: source .venv/bin/activate
tom@tom-VirtualBox:~/new_app$ source .venv/bin/activate

(new_app) tom@tom-VirtualBox:~/new_app$ python --version
Python 3.13.1

(new_app) tom@tom-VirtualBox:~/new_app$ ls
main.py  pyproject.toml  README.md  uv.lock
See that also Python version Python 3.13.1 is downloaded and used,i did not have this version on OS before.
Calab likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python use of virtual environments bre67e49 4 706 Feb-19-2025, 04:01 AM
Last Post: Sece1967
  Can a windows file be 'remapped' in Linux ? jehoshua 3 827 Dec-07-2024, 03:33 AM
Last Post: jehoshua
  Best practice on using virtual environments in Python bytecrunch 6 13,271 Feb-14-2024, 03:22 PM
Last Post: snippsat
  Virtual Environments - Organization (VS Code) JaysonWonder 11 3,884 Jan-26-2023, 11:34 PM
Last Post: Larz60+
  Keeping up with IDEs and Virtual Environments... bytecrunch 7 6,747 Sep-05-2022, 08:04 PM
Last Post: snippsat
  I don't understand pip and environments snakes 3 2,133 Jul-31-2022, 08:17 PM
Last Post: snakes
  How to compile a Python script for a Windows / Linux executable? netanelst 2 2,086 May-24-2022, 07:02 AM
Last Post: netanelst
  Resources for printing tabledata-Linux and Windows hammer 4 2,238 Apr-25-2022, 12:09 PM
Last Post: hammer
  Use different Anaconda environments on Linux Mint and Spyder StaLLoNe_CoBRa 0 2,444 Jan-20-2021, 03:12 AM
Last Post: StaLLoNe_CoBRa
  pip and venv virtual environments soupworks 2 2,962 Dec-30-2020, 11:38 PM
Last Post: soupworks

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020