Jump to content

Setting up venv on a linux box - my setup for a development-environment - using VSCode / ATOM / PyCharm and others more


dil_bert

Recommended Posts


Hello dear PHP-Fellows - dear Freaks

 

this thread covers some of my ideas regarding the Setting up venv on a linux box - my setup for a development-environment - using VSCode / ATOM / PyCharm and others more - well - first of all i am interested in setting up a python development-system.. -  - this is my first choice - besides this - of course i am interested in all thing php and also other languages..

 

here we go: After dealing some time with the installation and the setup of a development-enviroment on a linux box. 
and besides that on a Win10 too. i currently figure out which things are most important to set up a development  environment,.

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: 


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/python-virtual-environments-made-easy-fe0c603fe601
 
and this one Comparing Python Virtual Environment tools
https://towardsdatascience.com/comparing-python-virtual-environment-tools-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

$ 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.

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.

+------------------------+
|                        |
|                        |
|     python-workspace   |
|     ....-folder        |
|                        |
+----------+-------------+
           |
           |
           |              +----------------------+
           |              |                      |
           +--------------+     Project1         |
           |              |                      |
           |              +----------------------+
           |
           |              +----------------------+
           |              |                      |
           +--------------+     Project2         |
           |              |                      |
           |              +----------------------+
           |
           |              +----------------------+
           |              |                      |
           +--------------+     Project3         |
           |              |                      |
           |              +----------------------+
           |
           |              +----------------------+
           |              |                      |
           +--------------+     Project4         |
           |              |                      |
           |              +----------------------+
           |
           |              +----------------------+
           |              |                      |
           +--------------+    Project5          |
           |              |                      |
           |              +----------------------+
           |
           |              +----------------------+
           |              |                      |
           +--------------+   Project6           |
                          |                      |
                          +----------------------+
	


i think that this is a good 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

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:

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):

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.

.\.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.

\.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. 

 

   i will digg deeper and come back... 

yours  - dilbert

 

some good ressources:

Python Tutorial: https://code.visualstudio.com/docs/python/python-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[/QUOTE]


 

Link to comment
Share on other sites

  • 3 weeks later...


update: tried to install all anaconda-things according the official instruction - went the hard way - on terminal: see these docs: https://docs.anaconda.com/anaconda/install/linux/

a quick walktrough through the steps ended up in fully-fledged installation of Anaconda3

next steps are shown here: https://docs.anaconda.com/anaconda/user-guide/getting-started/

Linux: Open a terminal window and type anaconda-navigator.

voila - now Anaconda3 starts...

conclusio: all is fine now..

have a great day ;)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.