How do you organize your virtual environments?

twitter logo github logo ・1 min read

I am currently programming in Python at home and for each project I have a virtual environment, this practice avoid a lot of problems. A while ago I put virtual environments in their respective project directories, but that raised some issues with git and stuff...

So how do you organize your virtual environments? Is there a good practice for this?

me:
projects
β”œβ”€β”€ archives
β”‚Β Β  └── project1
β”œβ”€β”€ lab
β”‚Β Β  └── project2
β”œβ”€β”€ study
β”‚Β Β  └── project3
β”œβ”€β”€ venvs
β”‚Β Β  β”œβ”€β”€ project1venv
β”‚Β Β  β”œβ”€β”€ project2venv
β”‚Β Β  └── project3venv

In general, I organize my directories like @cecilelebleu , with just a few changes. See:

twitter logo DISCUSS (12)
markdown guide
 

Either use pipenv or poetry

I first used pipenv and it feels good(?). But there are some dependency problems which are stated on the page of poetry. That is why I am trying poertry for another project while using pipenv in other projects.

I can't understand how it is possible for a community that large to have:

  • pip + virtualenv but no fully reproducible enviroments and no dependency management
  • pipenv well, sometimes it is slow as f$?# and the dependency management is not the bes
  • poetry I don't know that much it to point out any negative aspects of it.

But yeah, I use pipenv regularly (for about half a year now) and am pretty fine with it. But still using poetry for the newest project to see how it works and if I like it more.

The only downside is to poetry is that PyCharm has no support for poetry. You need to set it up as a standard virtual environment in PyCharm, but that is not a real problem. You just have to know about that.

If someone has another tool I should give a shot which is actively in development and near feature complete I would give it a try.

//edited: Grammar, Spelling, Syntax of one or the other sentence; there might be more

 

I never used poetry, I'll try to use in some projects later, thanks for the comment <3

 

If you insist on using pip + virtualenv I think that virtualenvwrapper is a must.

It basically keeps all your venv's in one place and helps you switch between with autocompletion.

PS: pip + virtualenv is not avoidable in most cases: most open source libraries use it, and I am not sure that pipenv is suitable for libraries (and not just for top level applications)

 

I really like pip + virtualenv, I think virtualenvwrapper will be a usefull tool to me. Thanks for the comment!

 

pipenv environment at the root level of each project

I don't know if this is the proper way or not, so if anyone knows a better way, feel free to give me (us) tips.

 

I used it like that too, but sometimes I did git add. and sent my environment to Github by mistake.

 

It is ok to add the virtual environment in gitignore to personal projects, but what if the project is from another user? :/

 

I don't know if there is 100% correct way. For me it makes sense to keep an environment for projects alike as long as they are using same pip packages. One env per project seems like a good way to go too, if you have specific (pip packages or python) versions tied to a project.

In your case if all your environments are exactly the same (pip packages and python version) it would seem like an overkill to me.

 

Some projects use version 2.7 only. Besides having projects where I use different versions of some libraries ...

Classic DEV Post from Jun 12

What are your favorite Linux utility/productivity tools?

Leonardo Furtado profile image
CS Undergrad.
JOIN DEV NOW

We are a community