简体   繁体   中英

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.

设置>项目解释>齿轮按钮>添加>系统解释器 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?

设置>项目解释>齿轮按钮>添加> Virtualevn环境

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 eg 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.

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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM