I already shared how to create Virtual Environments using Anaconda, and also how to create shortcuts to use them directly in Windows Terminal (see references). This task is easy an amazing, however, at some point you may want to clean your environment.
That’s an easy task. I’m currently using Anaconda version 4.8.3. You can check your version with the command
To show your virtual environments, you must use the command
conda info --envs
Before deleting any of this, I checked them and … they use some space.
As you can see in the previous image
drone02, disk size is 2GB
p38, disk size is 1.4 GB
telloOpenCV, disk size is 2.6 GB
tfenv, disk size is 1.76 GB
I didn’t even check the other virtual environments. Right now I’m only using 2 from the total of 6 on the list, so I’ll delete the non used ones.
To delete a virtual environment we must use the command
conda env remove --name ENVIRONMENT
And with a simple command like this, I can remove the unused ones
Windows Terminal (WT) is one of the coolest tools I’ve using in the last couple of years. I’m not an expert, and not even a fan of CLIs, however I assume working with WT is super cool.
Bonus: If you speak Spanish, I shared my own thoughts about this with Juan and Eduard in a podcast episode here.
On top of this, I also use Anaconda a lot. And, now that we can launch and use Anaconda from a PowerShell Prompt, I think I should spend some time trying to figure out how to have Anaconda inside Windows Terminal.
I will assume that you know the basis of Windows Terminal profiles. As a WT user, we can create as many profiles as we want to have different tools available. This is my starting point to use Anaconda and Windows Terminal.
Note: Check References for Donovan Brown post about working with profiles.
Create a new profile to launch Anaconda in Windows Terminal
Let’s go to Windows Terminal Settings to create a new profile for Anaconda. In order to do this, I’ll copy and paste an existing profile, update the Guid and complete the following values.
guid: create and paste a new Guid
name: I defaulted this to Anaconda
commandline: this is the tricky one. So I’ll describe the steps below.
I browse to [C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Anaconda3 (64-bit)] and view the properties for the [Anaconda PowerShell Prompt]. Then copy the Target value and use the value in the commandline element.
// To view the default settings, hold "alt" while clicking on the "Settings" button.
Now I have a new environment named [drone], and I want to have a shortcut in Windows Terminal to open a new tab with this VirtualEnv activated. I copy & paste the definition of the Anaconda profile, used a new Guid, and added, the following command to the end of the line:
conda activate drone
As you can see in the previous image, when I open a new tab for my Drone Virtual Env, I already have it loaded. I also added a [cls] command at the end, so I can start with a clean environment.
Finally, and for reference, this is my current Windows Terminal settings file including the 2 Anaconda profiles.
After some posts about how to setup a Raspberry Pi, today I’ll share the steps I follow to install OpenCV.
Disclaimer: if you are looking for a detailed step by step on how to install or even build OpenCV in a Raspberry Pi, I strongly recommend to read the post “Install OpenCV on Raspberry Pi 4” by Adrian Rosebrock.
Ok, so let’s start. I assume that you read my posts and your Raspbian image is up and running.
Install Python 3 and Update device
1st step will be to install Python 3 with the following command
This process will take some minutes, so this is time 1 to get a coffee!
Install OpenCV and switch to right Raspberry Pi version!
And now the magic command to install OpenCV
sudo apt-get install libopencv-dev
And this process is the one who take most of the time, so coffee number 2. Take a look at all the dependencies for this
And after a couple of minutes the process is done. We can test the OpenCV version running 2 simple python commands. First let’s start python with the command
And then run the following lines
This should display the current OpenCV version.
However, with the latest version we have an error: ModuleNotFoundError: No module named ‘cv2’
The current installed version have some issues running in the raspberry py, so we need to make a downgrade to the version 188.8.131.52 with the command. We first uninstall the installed version (184.108.40.206) and install the specific version.
yesterday post, I created a new virtual environment named [devtf] and in this environment
I’ve installed a lot of tools that I need. Then I tried to launch a jupyter notebook
from this environment, to use this tools and, of course, it didn’t work.
It was time to read and learn how this works. So, when I finally get this I find this amazing article which really explain how this works “Using Virtual Environments in Jupyter Notebook and Python” (see references)
Jupyter Notebook makes sure that the IPython kernel is available, but you have to manually add a kernel with a different version of Python or a virtual environment. First, you need to activate your virtual environment. Next, install ipykernel which provides the IPython kernel for Jupyter. And finally, you can add your virtual environment to Jupyter.
Where “devtf” is the name of the new kernel you want to create. Now, when I launch Jupyter Notebooks, the new kernel is available to be used
When I started to use this new kernel (virtual environment) I realized that I didn’t installed TensorFlow. You know, being happy about this, naming the kernel TF but not installing the core component. And, sure, my notebooks didn’t work.
I went to my terminal / command prompt and installed TensorFlow. Then I only need to restart the Kernel, and everything start working. I added a extra couple of lines in my notebook just to check the TensorFlow and keras versions.
similar errors with another packages, so I pip installed the packages in the
terminal and restart the kernel to have the notebook OK. So, my simple reminder
for myself about how to do this!
today, and mostly a reminder on how to create a Virtual Environment in Python
in Windows 10. I’ve been doing this mostly in my Mac and my Raspberry Pi, and I
always forget how to do this on Windows, so … I’ll write this post to have this
Download the installers from the official Python source (see references). I usually install it on the root of my C: hard drive and name it with the version. In example: c:\Python37_64 folder.
also add this folder and the Scripts folder to the Environment Variables.
Note: Once you start to install tools which uses Python, your OS becomes a nightmare. You will have your own installed python, the version installed with Visual Studio, the one with Visual Studio Code, another one for Anaconda.
I’m not sure if this is a best practice or not, but I usually remove all the other versions and keep mines in the root of the C: drive.
Ok, let’s go
Let’s install virtualenv and the wrapper
pip install virtualenv virtualenvwrapper
Create new Virtual Environment
For a new
virtual environment named “testEnv”, open a command prompt and navigate to the
python folder. Then run the command
python -m virtualenv testEnv
couple of seconds, the virtual Environment will be installed, and you can use
it by run the [activate.bat] script. In this example
The virtual environment will be created at [c:\Python37_64\testEnv]
The virtual environment activate script will be at [c:\Python37_64\testEnv\Scripts\activate.bat]
So the full
command sequence is similar to this one
Now you have your virtual environment up and running and you may want to start to add your own packages or tools. Like in example: Numpy or to list the installed packages
Finally, you may leave the virtual environment with the command