The world’s leading publication for data science, AI, and ML professionals.

How To Solve Python Dependency Issues With Anaconda On Windows

Without changing absolute paths

In the last few days, I had some troubles with Python dependencies on my Windows machine.

I tried to install new packages to test them. Indeed, they were installed and I could see all the details with $ pip show [library_name] but when I tried to import the library installed a minute before I get import issues.

I had these issues using Jupyter Notebooks, so I thought it was somehow an Anaconda-related issue. This is was I did to try to solve the problem:

  • I tried to change the absolute path where all the Python (and Anaconda) packages were installed, but it resulted in a crash of Anaconda. So I had to restore the previous absolute paths.
  • I tried the "brute force": I opened VS CODE and installed the libraries I wanted to use on a virtual environment. And you know what? I had different dependencies issues…

So, after 2–3 hours of troubles, I decided to use the highest brute force possible, and I had three possibilities:

  • Uninstall and reinstall Python and Anaconda, but this would not solve the actual problems for several reasons (some files that may remain in the current folder could, anyway, let the paths remain the same and create the same issues, for example).
  • Uninstall and reinstall Windows on my machine.
  • Install Anaconda on a Ubuntu virtual machine.

Of course, I didn’t want to reinstall Windows, so I decided to use the third way, and I’m showing you how to do so, so that you can use this methodology if you need it.

Finally, since I mainly use Python for Data Science, I wanted to install Anaconda on my Linux machine so that I already have all the data-related libraries I need (and much more than just those).

But before going on…just consider that I was trying to install some less known, but yet powerful, Python libraries for data manipulation and scientific computation. I describe them in the following article:

Beyond Numpy and Pandas: Unlocking the Potential of Lesser-Known Python Libraries


Step 1: install a Linux virtual machine on Windows

The first step you need to perform is to install a Linux virtual machine on your Windows machine.

I describe this procedure in the following article in paragraph "How to use bash in Windows":

How to Easily Create an Alias in Bash to Speed Up Your Work (Even on Windows)

Don’t worry: you don’t need to be a "computer magician" (I’m not!). The procedure is pretty easy.

Step 2: update the operating system

After you’ve installed a Linux virtual machine, you launch the Linux terminal via "MobaXterm" (as described in the above-mentioned article) for example, and update the system via:

$ sudo apt update

$ sudo apt upgrade

Step 3: Download the installation file:

Now you can download the Anaconda installation file like so:

$ wget https://repo.anaconda.com/archive/Anaconda3-2023.03-1-Linux-x86_64.sh
NOTE: 

this was the installation file for my machine. 
Copy the file URL from the Anaconda website, depending on your machine 
like in the image below:

Step 4: execute the installation file

When you perform the wget command as in the previous step, at the end of the process the software will return the name of the installation file. It is something like that:

Copy the name of the file and execute it like so:

$ bash Anaconda3-2023.03-1-Linux-x86_64.sh

You’ll be asked to press "ENTER" several times.

Then, press "yes" to accept the installation conditions at the end of the process.

Step 5: restart the environment to make the installation effective

After accepting the condition in the previous steps, the software will ask you to close and open your shell (aka, MobaXterm if you used it) to make the installation effective:

When you open the shell again, you can verify the installation of Anaconda by typing:

$ conda --version

And in my case, I get:

Step 6: launch Jupyer Notebook

Ok, so Anaconda is installed, and to launch a Jupyter Notebook just type the following via MobaXterm:

$ jupyter notebook

and you can start using it!

Step 7: installing other libraries

Now, to install other libraries you may need (as in my case!), you can use WSL, so everything will be "connected", from a dependencies point of view, to the WSL environment and you won’t have troubles anymore.

This is because the WSL and the Windows environment are separated, and so are their dependencies.

In other words, just open your MobaXterm (or whatever you’re using), type pip install [new_library] and everything will work fine (until we break something new! 😁 ).


Conclusions

In this article, we’ve seen how we can install a Linux virtual environment to install Python and all its dependencies when we have issues on that on a Windows machine.

It seems long but, believe me: I struggled enough with the other ways I described at the beginning of this article to tell you that this is the fastest (and more secure) way to do so.


Hi, I’m Federico Trotta and I’m a freelance Technical Writer.

Want to collaborate with me? Contact me.


Related Articles