简体   繁体   English

为什么我不能在 Anaconda 之外导入 Python 模块?

[英]Why can't I import Python modules outside of Anaconda?

First, I've looked through other people's questions that sound similar and haven't found a situation like mine.首先,我查看了其他人听起来相似的问题,并没有发现像我这样的情况。 If you know of another post that solves my problem, I'm all ears (eyes, whatever).如果您知道另一篇可以解决我的问题的帖子,我会全神贯注(眼睛,无论如何)。

I have been using Spyder through Anaconda for most of my Python work up to now, but I don't really like it that much.到目前为止,我一直在通过 Anaconda 使用 Spyder 来完成我的大部分 Python 工作,但我不太喜欢它。 So, I'm trying to explore other IDEs, currently Atom.所以,我正在尝试探索其他 IDE,目前是 Atom。 I have set up Atom and cmd.exe to run Python from the Anaconda install by adding the.\Anaconda3 folder to my path.我已经设置了 Atom 和cmd.exe以从 Anaconda 安装中运行 Python,方法是将 .\Anaconda3 文件夹添加到我的路径。 I have also added the.我也加了。 \Anaconda3\Lib\site-packages and everywhere else I have found that anaconda has stored its modules (within the base environment). \Anaconda3\Lib\site-packages和其他我发现 anaconda 已经存储了它的模块(在基本环境中)。

Python runs fine in the Command Prompt and in Atom (using "script" package), but for some reason I cannot import any modules except sys and os unless I use either the Anaconda terminal or one of its included IDEs. Python 在命令提示符和 Atom 中运行良好(使用“脚本”包),但由于某种原因,除非我使用 Anaconda 终端或其包含的 IDE 之一,否则我无法导入除sysos之外的任何模块。 I can't even import numpy , though I can navigate to the site-packages folder in File Explorer and see it in there.我什至无法import numpy ,尽管我可以导航到文件资源管理器中的 site-packages 文件夹并在其中看到它。 Below is a screen shot showing side-by-side the Anaconda Prompt and Command Prompt.下面是并排显示 Anaconda 提示符和命令提示符的屏幕截图。 You can see that my path variable and executable are the same in both, but conda imports numpy just fine while cmd cannot.您可以看到我的路径变量和可执行文件在两者中都是相同的,但是conda imports numpy就好了,而cmd不能。 I would like to know why and how to fix it.我想知道为什么以及如何解决它。 All of the other questions I saw of this issue (StackOverflow and elsewhere) said to add the file path to the module to my PATH variable (which I have done) or run the program using the Anaconda executable (which I am doing).我在这个问题上看到的所有其他问题(StackOverflow 和其他地方)都说将模块的文件路径添加到我的PATH variable (我已经完成)或使用Anaconda executable运行程序(我正在做)。

Command Prompt vs Anaconda Prompt exectuable, path variable and importing numpy Command PromptAnaconda Prompt 、路径变量和导入numpy

Also, I searched for the ImportError (shown in the picture) on the internet and found a link to the Anaconda documentation saying to check the System32 folder for mkl related dll's but there weren't any in mine.此外,我在互联网上搜索ImportError (如图所示)并找到 Anaconda 文档的链接,说要检查System32文件夹中与 mkl 相关的 dll,但我的中没有。 Then I looked through the _distributor_init.py file in the numpy folder to figure out where it was trying to pull the _mklinit function from and see if maybe it was looking somewhere different from Anaconda.然后我查看了_distributor_init.py文件夹中的numpy文件,以找出它试图从哪里提取_mklinit function 并查看它是否看起来与 Z853F30A23CE8FCCBD6764 不同。 But if I understand correctly the "from. import" means that it's looking in the same numpy directory for that function and there is a file in there called _mklinit.cp37-win_amd64.pyd (which I can't look at the contents of, but it seems like a good candidate to me).但是,如果我理解正确,“from.import”意味着它正在与该 function 相同的numpy目录中查找,并且其中有一个名为_mklinit.cp37-win_amd64.pyd的文件(我无法查看其内容,但这对我来说似乎是一个不错的候选人)。 In any case, it seems like it looks in the same location for both Command Prompt and Anaconda Prompt, so that didn't help either.无论如何,对于命令提示符和 Anaconda 提示符,它似乎都在同一个位置,所以这也无济于事。

I was going to install Python separately from Anaconda, but I've heard that I can cause problems for myself unless I know what I'm doing (which I don't).我打算将 Python 与 Anaconda 分开安装,但我听说除非我知道自己在做什么(我不知道),否则我可能会给自己造成问题。 So, I would like to do this by just accessing the packages that Anaconda has, which everyone keeps saying I can do but it isn't working for me so far.所以,我想通过访问 Anaconda 拥有的包来做到这一点,每个人都说我可以做到,但到目前为止它对我不起作用。

It's possible I'm dumb, but I don't get it.可能我很笨,但我不明白。 Any help would be appreciated.任何帮助,将不胜感激。

Running:跑步:

Windows 10 Windows 10

Python 3.7.4 Python 3.7.4

Anaconda 4.8.3 Anaconda 4.8.3

I've been trying to work this out for sometime.我一直在努力解决这个问题。 My Anaconda Python is 3.8.我的 Anaconda Python 是 3.8。 Before installing Anaconda I had Python 3.9 installed.在安装 Anaconda 之前,我安装了 Python 3.9。 I sometimes wanted to use my 3.9 Idle but pip always put added packages into Anaconda.我有时想使用我的 3.9 Idle,但 pip 总是将添加的包放入 Anaconda。 The Python Documents tell you how. Python 文档告诉您如何操作。 file:///Library/Frameworks/Python.framework/Versions/3.9/Resources/English.lproj/Documentation/installing/index.html. file:///Library/Frameworks/Python.framework/Versions/3.9/Resources/English.lproj/Documentation/installing/index.html。

In my MacBook Pro Terminal I entered (as an example).在我的 MacBook Pro 终端中,我输入了(例如)。 It worked.有效。

python3.9 -m pip install torchvision python3.9 -m pip 安装torchvision

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

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