Further Notes On Virtual Environments

Further Notes On Virtual Environments

Due to team capacity I am 100% blocked and so I have nothing other to do than to continue to work on my virutal environments tute. So let's keep going. I am having a bad day. So what are the benefits of virtual environments, one more time? Allow you to create lightweight and isolated environments. 

It allows you to isolate and manage your dependencies separately for each project. This I have known since the beginning - but it has been different to implementing them and understanding them in practice. the command to set up a virtual environment is -m venv path/to/venv/. I do know this too but it's always good to remember. This tutorial seems to be a bit Windows and VSCode leaning and I am PyCharm and Mac. But okay yeah - nevermind. The tutorial does cover other packages for creating virutal environments, but I'll be ignoring those. 

Most of my practice might come in the actual tutorial so it will just be in the code. But any cool new learnings I'll add here - thanks. 

Learnings

  • -m tells Python to "run a library module as a script"
    • What does that mean? 
    • So with -m, you tell Python
      • "Find this module in my installed packages or the standard library, and run it as if it were a script."

venv as a module

Okay so there is a Python module that is named venv that literally takes care of venvs. I didn't know this. You can call your virtual environment whatever you want; I knew this, of course. Stupid as this may sound, I just want to confirm this; you know that you are in your virutal environment when you can see it in brackets on the side. Now you can begin to install your external packages - hooray! 

Installing Packages

Okay so this is where I get even more lost. In the tutorial it tells me to pip install things. That's great - I can't wait to do it. But at work I'm pretty sure that we don't pip install things. Um - whoops. But it's great for the demo. Here we are now onto the crux of my learnings for today:

Why it was worthing having installed a virtual environment

It was worth having installed a virtual environment because - "because you first created and activated the virtual environment, `pip` will install the packages in an isolated location." The main thing here is the reward. Why was it worth it? Because. "The packages are installed in an isolated location." Boom. Now I understand it. That's why we bother with it. Wow. "You can now install packages to your virtual environment." "To get to this point, you created a virtual environment named venv and then activated it in your current shell session." So do get to the point where you can install isolated packages you have to
  • Create a virtual environment
  • Activate it
The tute seems to say to install packages but I can't decide what packages to install help! I panicked but then my wonderful and lovely colleague told me what to do and now I have a practice venv with
  • numpy 
  • matplotlib
  • and panadas
in it. YAYYYYY HOORAY!

Other Notes

  • Pycharm automatically recognises and activates your virtual environment for you
  • Now this tute is talking about interpreters and venvs in python and these have always thrown me
  • Are they the same thing?
  • Apparently a virtual environment wraps an interpreter?
  • Oh so help me God
A black outline of shiva and text describing

Okay so a virtual environment contains everything - including the interpreter - and possibly any other packages xxx

Comments

Popular posts from this blog

Hello World

“But yesterday, I heard God say, you were born to be the one…”

In the Water, I find Fire