4 ms·
1) Create a virtual environment. python3 -m venv myproject (download an interpreter). 2) Run pip install. myproject/bin/activate; pip install requirements.txt;
by user5994461 6y ago
1) Create a virtual environment. python3 -m venv myproject (download an interpreter).
2) Run pip install. myproject/bin/activate; pip install requirements.txt; (download all project dependencies).
3) Start the application. myproject/bin/activate; python myapp.py
If you can assume that there is an interpreter available on the system, say /usr/bin/python3, you can use that instead of creating a virtual environment.
If you want to embed all the dependencies, you can save all the files created by pip install in the /lib directory if I remember the name well.
Should I write a full blog post with example? I used to deploy python applications in a bank, can explain all the advanced usage with and without internet access, with and without dependencies.
- aerovistae 6y agolord yes
- nemosaltat 6y agoSeconded
- williamtwild 6y agoyes pleasr
- simonebrunozzi 6y agoYes, please. Aaaand, now that you're at it, a single .dmg file for MacOS with binaries and scripts so us lazy people with Macbooks can start coding right away :) (it might be a bit inaccurate but I guess you know what I mean)
- somurzakov 6y agoyes please
- cvhashim 6y agoThat would be awesome
- noitpmeder 6y ago" you can assume that there is an interpreter available on the system, say /usr/bin/python3, you can use that instead of creating a virtual environment." Please DO NOT do this. It is so much easier to always create a virtual environment, and then you never have to worry about installing two applications on the same system that may have conflicting versions. Additionally, you don't know what else may be installed into the system's default python environment.
- jamestimmins 6y agoI find you're better off pretending that your system doesn't have any builtin Python. I use virtual environment for everything.
- ptx 6y agoUsing the system Python for scripts that only depend on the standard library should be pretty safe. As soon as I need any third-party dependency I create a virtual environment. Edit: Although if startup performance is important, using a virtual environment might be a good idea even for simple scripts. Running a "hello world" program using the system Python takes twice as long on my system as running it with "python -S" (i.e. ignoring site packages) or from a fresh virtual env.