Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use anaconda in pycharm (Import libraries error, updating anaconda and virtual environment)

What I was doing before

When I start using Anaconda in pycharm before, I installed Anaconda and after that I installed pycharm. Running the pycharm and in the following menu (following image) I did choose the ~/Anadaconda/python.exe path for the pycharm interpreter and I used this interpreter for all my project. I hadn't any problem.

Setting > Project Interpret>Gear button > Add > System Interpreter Question 1: Is this procedure correct?

There is something called Virtualenv Environment in the picture. As far as I know, this makes a project and its dependencies isolated. I didn't fully understand what is the use of that though.

Question 2: What is the use of isolating the projects? Why should I do that? (an example would be helpful)

Of Course, there is a benefit and use of that, so 3rd question comes here. There is a checkbox that says Make it available for all project Is still this option follows being isolated?

Setting > Project Interpret>Gear button > Add > Virtualevn Environment

Real Problem

The problem starts a week ago when I want to install the new version of Anaconda 3.5.1. and I did. but I wish I didn't. After doing that, for every package I import to my project, I get an error, it seems like, it doesn't recognize them at all. for e.g. Numpy:

module = self._system_import(name, *args, **kwargs)

ImportError: DLL load failed: The specified module could not be found.

During handling of the above exception, another exception occurred:

For sklearn:

ImportError: Importing the multiarray numpy extension module failed. Most likely you are trying to import a failed build of numpy.

If you're working with a numpy git repo, try git clean -xdf (removes all files not under version control). Otherwise reinstall numpy.

Original error was: DLL load failed: The specified module could not be found.

Tired reinstall both pycharm and anaconda for a few times. I'm getting crazy about this.

like image 920
Pedram Avatar asked Dec 10 '18 16:12

Pedram


People also ask

Why is PyCharm not importing modules?

Troubleshooting: Try installing/importing a package from the system terminal (outside of PyCharm) using the same interpreter/environment. In case you are using a virtualenv/conda environment as your Project Interpreter in PyCharm, it is enough to activate that environment in the system terminal and then do the test.


2 Answers

The procedure you use to setup the interpreter is correct. The use of isolating projects is that you don't get in trouble with package dependencies. Some projects could require different versions of, for instance the sk-learn package. Isolating projects by using environments and installing seperate packages for every project prevents any issues with this. "Make available to projects" has nothing to do with isolation of packages inside that environment.

The problem here is that you probably did not tick the option 'Add to path' while installing Anaconda. PyCharm does not automatically activate your environments when you do not add Anaconda to path. Using PyCharm with an unactivated environment is unsupported, and can lead to import-errors like the ones you specify. So to solve your error, use anaconda prompt, activate your environment and launch PyCharm from there, or re-install anaconda/mini-conda with the option "add-to-path" checked. A detailed discussion of this problem can be found here.

like image 156
Psychotechnopath Avatar answered Oct 02 '22 10:10

Psychotechnopath


Yes, a virtual environment is exactly that.

Using a virtual environment is kind of a clean slate. You wouldnt want you to use a environment for a web crawler that has Django in it. And in your Django site you wouldnt want to have BeautifulSoup in it. This is the best way of managing environments within different projects. I would highly recommend setting up a virtual environment for each project you create.

Now when you are getting these errors. First do you have pip updated to the latest version? When installing numpy are you using a CLI or the using the pycharm wizard thingy?

Sometimes when you get errors installing you can use easy install instead of pip and it can resolve the issue.

like image 29
Alex D Avatar answered Oct 02 '22 11:10

Alex D