简体   繁体   中英

Python packages (numpy/pandas/etc) in Visual Studio 2017 on Windows

I've just installed Visual Studio Community with the workloads for Python and Data Science.

I create a new Regression project from the Python\\Machine Learning template.

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.

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.

If I'm lucky, then I get past the above error to this one: Importing the multiarray numpy extension module failed. .

Anyone got any pointers for setting this up?

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.

Anaconda needs to add for pandas,numpy, and pyplot. Add Anaconda on right click on Python Environment and add the Anaconda.

I just went through this pain the other day, on 64-bit Windows 7 with 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.

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

On my machine pandas, numpy and matplotlib sit in

C:\\Program Files\\Python36\\Lib\\site-packages

Hope this may help.

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

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.

That seemed to do the trick, after restarting Visual Studio.

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