ermalgashi / blog-project

0 stars 0 forks source link

"Python Virtual Environments" #2

Open ermalgashi opened 2 years ago

ermalgashi commented 2 years ago

When starting the project do we use Python Env and how would we ignore those files from uploading to the git?

mekhami commented 2 years ago

Yeah! You absolutely want to use a virtual environment. It's important to get that set up straight away to avoid issues with libraries when you're trying to run the project.

A good pattern is to keep a folder for all your virtual environments that is outside of the project folder. So I keep one in my home folder, ~/.venvs and whenever I want to create a virtual environment I use that folder to put it in.

Since python has first-class support for virtual environments now (https://docs.python.org/3/library/venv.html) we can make use of this. Try this out a bit and see what you can do.

ermalgashi commented 2 years ago

Having a folder with all the ven-vs in one place seems a pretty good idea, does it helps with ignoring files and not uploading them to git also.

So "pyenv" is not recommended anymore instead we use "python3 -m venv", after creating a virtual env for a project we name it with the project name on the specified folder for the ven-vs, and always when starting the project we activate the venv with the source command. We use pip to install new apps in the venv, and we use "pip freeze > requirement_file.txt" to manage our dependencies for the said project. Since in the future we are going with "Python Poetry" only our first project will be using the pip freeze to keep track of dependencies.

mekhami commented 2 years ago

pyenv is still great, but it's something we'll get into later. it makes a lot of stuff easier, but it's an extra thing to learn that will just make all of this harder now.

for now we'll stick with the python3 venv, we'll make sure to activate that environment when we're working on the project, and use a normal requirements.txt file for dependencies.

You got it.

ermalgashi commented 2 years ago

Yeah 100%