Windows 上 Visual Studio 2017 中的 Python 包(numpy/pandas/etc)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45060697/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python packages (numpy/pandas/etc) in Visual Studio 2017 on Windows
提问by Sean
I've just installed Visual Studio Community with the workloads for Python and Data Science.
我刚刚安装了带有 Python 和数据科学工作负载的 Visual Studio Community。
I create a new Regression project from the Python\Machine Learning template.
我从 Python\Machine Learning 模板创建了一个新的回归项目。
The first few lines are:
前几行是:
from pandas import read_table
import numpy as np
import matplotlib.pyplot as plt
First I get the errors: No module named xxx
or Missing required dependencies [xxx]
, for pandas or numpy, or scikitlearn or scipy.
首先我得到错误:No module named xxx
or Missing required dependencies [xxx]
,对于熊猫或 numpy,或 scikitlearn 或 scipy。
I would have expected these to be installed as part of the Visual Studio workloads, and indeed they seem to be in the Anaconda3\Lib\sitpackages
folder, if that's where they should be. But I tried installing them anyway from the Python Environments window in VS.
我原以为这些会作为 Visual Studio 工作负载的一部分安装,而且确实它们似乎在Anaconda3\Lib\sitpackages
文件夹中,如果它们应该在那里的话。但是我还是尝试从 VS 中的 Python Environments 窗口安装它们。
If I'm lucky, then I get past the above error to this one: Importing the multiarray numpy extension module failed.
.
如果我很幸运,那么我就会克服上述错误到这个错误:Importing the multiarray numpy extension module failed.
.
Anyone got any pointers for setting this up?
任何人都有设置这个的任何指示?
回答by AS Mackay
I just went through this pain the other day, on 64-bit Windows 7 with VS 2017 Community.
前几天我刚刚在 64 位 Windows 7 和 VS 2017 Community 上经历了这种痛苦。
To get the regression example working I had to upgrade Python to version 3.6.1, as the pip-installed version of numpy (1.13.1) doesn't work with 3.6.0.
为了使回归示例正常工作,我必须将 Python 升级到 3.6.1 版,因为 pip 安装的 numpy (1.13.1) 版本不适用于 3.6.0。
In short, I downloaded and ran the Windows 64-bit installer for Python 3.6.1 direct from python.org, then (as you described above) from the VS Python Environments window installed matplotlib (2.0.2) numpy (1.13.1) and pandas (0.20.3). After that, all the imports worked. (NB it takes a while for the VS intellisense feature to get up to speed with the imports.)
简而言之,我直接从 python.org 下载并运行了适用于 Python 3.6.1 的 Windows 64 位安装程序,然后(如上所述)从 VS Python Environments 窗口安装了 matplotlib (2.0.2) numpy (1.13.1)和熊猫(0.20.3)。之后,所有的进口工作。(注意 VS 智能感知功能需要一段时间才能跟上导入的速度。)
On my machine pandas, numpy and matplotlib sit in
在我的机器熊猫,numpy 和 matplotlib 坐在
C:\Program Files\Python36\Lib\site-packages
C:\Program Files\Python36\Lib\site-packages
Hope this may help.
希望这可能会有所帮助。
回答by Sean
This seems to have got it working:
这似乎让它工作了:
I installed the latest version of Anaconda (after uninstalling the version that came with the Python VS workload).
我安装了最新版本的 Anaconda(在卸载了 Python VS 工作负载附带的版本之后)。
Then I installed the numpy, scipy and scikit wheels from this link. Importantly, I installed them using the Anaconda console (Start -> Anaconda Prompt [Run as Administrator]), as I had another system installation of Python, that I had been installing the wheels/packages into previously.
然后我从这个链接安装了 numpy、scipy 和 scikit 轮子。重要的是,我使用 Anaconda 控制台(开始 -> Anaconda Prompt [以管理员身份运行])安装它们,因为我有另一个 Python 系统安装,我之前一直在安装轮子/包。
That seemed to do the trick, after restarting Visual Studio.
重新启动 Visual Studio 后,这似乎奏效了。
回答by Zwitterion
This is how I got it to work: Right click on "Python Environments" on the solution explorer window. Select Add/Remove python environments and then pick an environment that has the right packages selected or add packages as needed.
这就是我让它工作的方式:右键单击解决方案资源管理器窗口中的“Python 环境”。选择添加/删除 python 环境,然后选择一个环境,选择了正确的包或根据需要添加包。
回答by sachit
Anaconda needs to add for pandas,numpy, and pyplot. Add Anaconda on right click on Python Environment and add the Anaconda.
Anaconda 需要为 pandas、numpy 和 pyplot 添加。右键单击 Python Environment 添加 Anaconda 并添加 Anaconda。