简体   繁体   English

在pycharm中使用anaconda(导入库错误,更新anaconda和虚拟环境)

[英]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. 当我开始在pycharm中使用Anaconda之前,我安装了Anaconda,之后我安装了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. 运行pycharm并在下面的菜单中(下图)我选择了pycharm解释器的~/Anadaconda/python.exe路径,我将这个解释器用于我的所有项目。 I hadn't any problem. 我没有任何问题。

设置>项目解释>齿轮按钮>添加>系统解释器 Question 1: Is this procedure correct? 问题1: 此程序是否正确?

There is something called Virtualenv Environment in the picture. 图中有一种叫做Virtualenv Environment东西。 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? 问题2: 隔离项目有什么用? 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? 有一个复选框,说Make it available for all project ”这个选项是否仍然被隔离?

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

Real Problem 真正的问题

The problem starts a week ago when I want to install the new version of Anaconda 3.5.1. 问题始于一周前,当我想安装新版本的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: 比如Numpy:

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

ImportError: DLL load failed: The specified module could not be found. ImportError:DLL加载失败:找不到指定的模块。

During handling of the above exception, another exception occurred: 在处理上述异常期间,发生了另一个异常:

For sklearn: 对于sklearn:

ImportError: Importing the multiarray numpy extension module failed. ImportError:导入多阵列numpy扩展模块失败。 Most likely you are trying to import a failed build of numpy. 您很可能正在尝试导入失败的numpy版本。

If you're working with a numpy git repo, try git clean -xdf (removes all files not under version control). 如果您正在使用numpy git repo,请尝试git clean -xdf (删除所有不受版本控制的文件)。 Otherwise reinstall numpy. 否则重新安装numpy。

Original error was: DLL load failed: The specified module could not be found. 原始错误是:DLL加载失败:找不到指定的模块。

Tired reinstall both pycharm and anaconda for a few times. 厌倦了几次重新安装pycharm和anaconda。 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. 有些项目可能需要不同版本,例如sk-learn包。 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. 这里的问题是你在安装Anaconda时可能没有勾选“添加到路径”选项。 PyCharm does not automatically activate your environments when you do not add Anaconda to path. 当您不将Anaconda添加到路径时,PyCharm不会自动激活您的环境。 Using PyCharm with an unactivated environment is unsupported, and can lead to import-errors like the ones you specify. 不支持将PyCharm与未激活的环境一起使用,并且可能导致导入错误,例如您指定的错误。 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. 因此,要解决您的错误,请使用anaconda提示符,激活您的环境并从那里启动PyCharm,或者选中“add-to-path”选项重新安装anaconda / mini-conda。 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. 您不希望您将环境用于其中包含Django的Web爬网程序。 And in your Django site you wouldnt want to have BeautifulSoup in it. 在您的Django网站中,您不希望其中包含BeautifulSoup。 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? 首先你有pip更新到最新版本? When installing numpy are you using a CLI or the using the pycharm wizard thingy? 安装numpy时你使用的是CLI还是使用了pycharm向导?

Sometimes when you get errors installing you can use easy install instead of pip and it can resolve the issue. 有时,当您安装错误时,可以使用简易安装而不是pip,它可以解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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