LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-02-2020, 01:46 PM   #1
rincon
LQ Newbie
 
Registered: Mar 2020
Posts: 20

Rep: Reputation: Disabled
Setting up venv on a linux box: how to get rid of the dependencies-hell


Hello dear Linux-Fellows


i am pretty new to this site - this is my very first question. I hope that it is written well

After dealing some time with the installation and the setup of a development-enviroment on a linux box (MX-Linux 19.1 ) and besides that on a Win10 too. i need your advice.

i have installed Python in a global mode and fashion. And i guess that this causes issues all along the way.

BTW: guess that it surely is worth to look into docker (and perhaps into Anaconda too - since i guess that i might get rid of the hell of dependencies... note: i am installing all that stuff on both on ... a. on win 10 and b. on linux ?


i have read some and have seen a whole bunch of tutorials on the setup virtual environment for Python

- in VS Code - best practices for using Virtualenv
- and besides for ATOM ...

i am very very glad that you have posted and give me some important hints:


Quote:
it semms like the package which i installed and the project's environment i am currently using is different.
the package which i have installed was in the global environment: " c:\program files\python37\lib\site-packages ", and well it seems like i looks like using the environment different(maybe the environment related to the project): This said i try ton identify this by look the right left coner shows which environment i am currently using now.

So i guess that i have to using virtualenv to isolate my projects and then i store pip dependencies in requirements.txt.
As we develop, we install, remove and upgrade packages, the list of dependencies in your project differs from requirements.txt

but how can i do it right - how to setup venv the right way -
a. on win 10 and
b. on linux ?

i have setup a python-development-environment on a Windows 10 machine and on a MX-Linux-machine.
i guess that i set up the machine /ATOM badly - any and all help greatly appreciated.


note: the setup of Python with global mode is weird so weird.

regarding the set up and usage of virtual environment in VSCode

I recently have read an article on using Virtual Environments for Python projects.
https://towardsdatascience.com/pytho...y-fe0c603fe601

and this one Comparing Python Virtual Environment tools
https://towardsdatascience.com/compa...s-9a6543643a44

guess, that have to take care how i setup python on my linux-machine.

Comparing installed pip packages with requirements.txt :: So if we are using virtualenv to isolate our projects and then subsequently we store pip dependencies in requirements.txt. As we develop, we install, remove and upgrade packages, the list of dependencies in your project differs from the so called requirements.txt

Currently Installed Packages: To list what are the packages that are actually installed, we can run

Code:
$ pip freeze
Compare Differences: A simple comparison of requirements.txt and pip freeze will fail because the packages are in different order.
sort both of the output then compare them with pip

to sume up: some of the best Practices are the following:

- Always make sure requirements.txt reflects the actual dependencies
- Pin package dependencies - use the exact version
- Preferably track only the top level dependencies in your requirements.txt
- Update dependencies periodically - year but how
- Consider using pip-compile and pip-sync to manage your dependencies. Use pur to automatically update your top level dependencies in requirements.txt


I am starting to work on VS-Code using venv: In my project folder I guess that i have to create venv folder.

Code:
python -m venv venv /path/to/new/virtual/environment
but when i run in VS Code the command select python interpreter my venv folder is not shown.

to make sure that i do all okay i try the following steps
to make my virtual interpreter in VS Code visible? i

1. just go to File > preferences > Settings - afterwards i

2. click on Workspace settings.

3. Under Files: Association, we will find Edit in settings.json , Well i click on that.


4. Update "python.pythonPath": "my_venv_path/bin/python" under workspace settings.

(For Windows): Update "python.pythonPath": "my_venv_path/Scripts/python.exe" under workspace settings. And subsequently

5. Restart VSCode incase if it still doesn't show the venv.


another option to show virtual environments in vs code:

go to the parent folder in which venv is there through command prompt.
Type code . and Enter. [Working on both windows and linux for me.]

That should also show the virtual environments present in that folder.

In one workspace folder named Python need to adde all my other projects.

to spell it out clearly:

- I would have to have only one venv for the whole workspace folder Python.
- i add each subfolder in Python folder as a workspace project like Project1, Project2, Project3, Project4, Project5, Project6 etc.

In that Project folder I created venv environment and edited settings.json for workspace with this "python.venvPath": "venv" .
Now, for every new project I will create new workspace and inside that folder goes venv folder which will be automatically recognized.



Code:
+------------------------+
|                        |
|                        |
|     python-workspace   |
|     ....-folder        |
|                        |
+----------+-------------+
           |
           |
           |              +----------------------+
           |              |                      |
           +--------------+     Project1         |
           |              |                      |
           |              +----------------------+
           |
           |              +----------------------+
           |              |                      |
           +--------------+     Project2         |
           |              |                      |
           |              +----------------------+
           |
           |              +----------------------+
           |              |                      |
           +--------------+     Project3         |
           |              |                      |
           |              +----------------------+
           |
           |              +----------------------+
           |              |                      |
           +--------------+     Project4         |
           |              |                      |
           |              +----------------------+
           |
           |              +----------------------+
           |              |                      |
           +--------------+    Project5          |
           |              |                      |
           |              +----------------------+
           |
           |              +----------------------+
           |              |                      |
           +--------------+   Project6           |
                          |                      |
                          +----------------------+
how do you like this idea!?



some additional ideas:

Attention: I was trying to make my project directory and the virtual environment one and the same - which isn't correct.

I have a \Code\Python directory where I store all my Python projects.

My
Code:
Python 3 installation is on my Path.
If I want to create a new Python project (Project1) with its own virtual environment, then I do this:

Code:
python -m venv Code\Python\Project1\venv
Then, simply opening the folder (Project1) in Visual Studio Code ensures that the correct virtual environment is used.



some words about the creation of a new environment in VSCode

we can create a new environment in VSCode, if were just running the following command ( well genearlly spoken we can use “.env” as name of the environment):

Code:
python -m venv .name_of_environment
note: it is possible to use the PowerShell as terminal in VSCode, we are able to run the ps1 file.

Code:
.\.name_of_environment\Scripts\activate.ps1
ther is another option: we also can use the command prompt as terminal in VSCode. If we doso then we can run the bat file.

Code:
\.name_of_environment\Scripts\activate.bat
the good thing: vscode shows up in the bottom left corner the progress:

if we just click on the the Python 3.X.X and then we can see the active executable is pointing to the python.exe in our virtual environment folder.

this is allmost in every case possible and doable. If not - then were able to select it from the dropdown. This should now be indicated in the bottom left of VS Code. one main goal is to ensure that the virtual environment has been created inside the folder from our workspace if - for the seldom case it happens that it was created outside the folder from our workspace, then we can rework this a bit. In this case, VS Code doesn’t pick it up automatically we need to fix this.



how do you like this idea!?

yours rincon - allways going the hard way
learing Python the hard way


some good ressources:

Python Tutorial: https://code.visualstudio.com/docs/p...ython-tutorial

virtual environment - the legendary hitchhiker-guide
https://docs.python-guide.org/dev/virtualenvs/

Python Tutorial: VENV (Mac & Linux) - How to Use Virtual Environments with the Built-In venv Module
a video by corey schafer: https://www.youtube.com/watch?v=Kg1Yvry_Ydk

Last edited by rincon; 04-04-2020 at 03:21 PM.
 
Old 04-02-2020, 04:20 PM   #2
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 9,970

Rep: Reputation: 4563Reputation: 4563Reputation: 4563Reputation: 4563Reputation: 4563Reputation: 4563Reputation: 4563Reputation: 4563Reputation: 4563Reputation: 4563Reputation: 4563
I just activate the virtual environment before starting VSCode (from the command line in the same terminal).
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to intall sdl2 without dependencies hell? siery Linux - Newbie 5 12-31-2017 04:51 AM
How to get rid of dialog box asking permission to store info and space in FB? trien27 Linux - Software 3 07-03-2011 12:07 PM
LXer: Secure the Hell Out of Your Linux box LXer Syndicated Linux News 0 05-10-2008 03:30 PM
Because of "dependencies" hell,... me210 Fedora 4 01-18-2007 05:00 AM
Another dependencies hell. nidua18 Linux - Software 4 09-27-2003 01:12 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration