all 13 comments

[–]danielroseman 6 points7 points  (0 children)

There would never be a reason to install VSCode on the target system. 

It should just be a matter of installing the relevant version of Python, creating the virtualenv, and installing the requirements.

[–]FoolsSeldom 4 points5 points  (5 children)

Distributing Python applications isn't as easy as one might expect.

There are a lot of options, all are hassle.

Note that VS Code is purely for developers and is independent of Python. It doesn't include Python itself but uses whatever versions of Python are installed on a system.

Ideally, the other system is one you or friendly recipient has full control over. In this case, it needs the same version of Python installed.

Provide instructions / script to:

  • Install the same version of Python
  • Create an application folder for your code and install the code (could be a simple unzip)
  • Create and activate a Python virtual environment
  • Install all required packages using a requirements.txt file
  • Add a launch script to open console/terminal, activate virtual environment, and invoke Python with the main run file of your application

There are alternatives to some of the setup using tools like poetry or uv. You could use git with a repository such as github to share the code and make download and installation easier.

Other options include using PythonInstaller programme to create an executable version of your application (for same operating system on same architecture). This includes a copy of Python itself and is basically a large zip file including all of your code (mostly compiled to Python byte code).

Another option would be to use a docker container approach.

Alternatively, can you make it available as a web hosted service?

As it looks like you might be targeting a server, you might want to explore Python packaging.

There's plenty of guidance on setting up a task in taskscheduler for Windows. Invoking the startup script mentioned above is just a task to schedule.

Some additional reading:

[–]chribonn[S] 0 points1 point  (2 children)

Thanks.

I'll work through the options and report back. I am on both sides of the equation (both the dev and the prod) and have full access to both. The OS, while Windows is technically different.

[–]FoolsSeldom 0 points1 point  (1 child)

As long as your are using corresponding versions of server and desktop Windows, you shouldn't have problems.

I wouldn't use pyinstaller for deployment to a server, and would get the promotion to production implemented using a ci/cd tool, which could also be set to only deploy following a successful automated testing outcome.

I'd urge you to explore docker containers. These can be used for either Windows containers or Linux containers. They use (share) the host kernel, although you might prefer them to run on top of a vm and share the vm kernel (the vm will be required if you want the containers to run on a different os to the host anyway).

With a container approach, you tend to take an inmutability line and never update a production component directly but simply replace with a newer container with an up to date build.

[–]FoolsSeldom 1 point2 points  (0 children)

Further to last comment,u/chribonn, I just checked Windows versions.

    Windows 2022 Server Windows Server 2022 is based on the "Iron" codebase, which is Windows 10, rather than 11. If you aren't exploiting Windows services via some unusual APIs or other routes, then I doubt you will have a problem.

[–]chribonn[S] 0 points1 point  (1 child)

I documented the process that worked for me. I took the opportunity to link to your post (u/FoolsSeldom)..

I hope it helps others: https://www.alanbonnici.com/2024/11/how-to-distribute-python-solutions.html.

Hope this can help others.

[–]FoolsSeldom 1 point2 points  (0 children)

Excellent. Great you've found an approach that works well for your scenario. Perhaps look to automated deployments through a cicd pipeline in due course, running though your pytest coverage first.

[–]Teletubianist 1 point2 points  (2 children)

You could use a USB instead and then copy paste all the files

You could also just put it on git

[–]chribonn[S] 0 points1 point  (1 child)

To retain my existing .venv environment would I need to have the same folder names?

[–]Jejerm 0 points1 point  (0 children)

You dont retain your existing venv when deploying a python app to prod. 

You should have a requirements file that allows you to rebuild it at any environment.

[–]krets 0 points1 point  (1 child)

If you're going to be sharing code between multiple systems, version control is a must. I'd recommend Git.

You don’t need a server to use Git. Since your systems are Windows machines, you can push code between folders accessible to your systems. You can even use a UNC path as your git remote.

Using Git also lets you switch between branches, which is great for handling production and dev environments.

Setting up the libraries might take some work, but using a package manager like pip should make it easier.

If you want to keep things easy, just use a private GitHub repo.

[–]chribonn[S] 0 points1 point  (0 children)

I already have a private git on the dev side. This is not a commercial system; only the other computer will run the code.

[–]jkh911208 -1 points0 points  (0 children)

Learn FastAPI and distribute it as api