将 Pandas 导入 Python

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39771274/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 02:06:27  来源:igfitidea点击:

Import Pandas Into Python

pythonpandasimporterrorpython-3.5

提问by polonius11

I just installed Python 3.5.2. I am working in the shell/IDLE environment and attempting to import Pandas.

我刚刚安装了 Python 3.5.2。我在 shell/IDLE 环境中工作并尝试导入 Pandas。

However when I write: import pandas

但是,当我写:导入Pandas

I get the following:

我得到以下信息:

Traceback (most recent call last):
  File "C:/Users/bartogre/Desktop/Program1.py", line 1, in <module>
    import pandas
ImportError: No module named 'pandas'

How do I add any module to the library Python 3.5.2 is reading? I do not want to work in Anaconda.

如何将任何模块添加到 Python 3.5.2 正在读取的库中?我不想在 Anaconda 工作。

I watched this video: https://www.youtube.com/watch?v=ddpYVA-7wq4

我看了这个视频:https: //www.youtube.com/watch?v=ddpYVA-7wq4

And below is my output from CMD:

下面是我从 CMD 的输出:

C:\Users\bartogre>
C:\Users\bartogre>cd c:\users\bartogre\desktop\pyodbc-master
c:\Users\bartogre\Desktop\pyodbc-master>python setup.py
c:\Users\bartogre\Desktop\pyodbc-master>python setup.py install

'git' is not recognized as an internal or external command,
operable program or batch file.
WARNING: git describe failed with: 1
WARNING: Unable to determine version.  Using 3.0.0.0
C:\Program Files (x86)\Anaconda3\lib\site-packages\setuptools-27.2.0-py3.5.egg\s
etuptools\dist.py:340: UserWarning: The version specified ('3.0.0-unsupported')
is an invalid version, this may not work as expected with newer versions of setu
ptools, pip, and PyPI. Please see PEP 440 for more details.
running install
running bdist_egg
running egg_info
writing pyodbc.egg-info\PKG-INFO
writing dependency_links to pyodbc.egg-info\dependency_links.txt
writing top-level names to pyodbc.egg-info\top_level.txt
reading manifest file 'pyodbc.egg-info\SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'pyodbc.egg-info\SOURCES.txt'
installing library code to build\bdist.win32\egg
running install_lib
running build_ext
building 'pyodbc' extension
error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++
Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools

采纳答案by Terry Jan Reedy

A bit of background: a system can have multiple Python installations. On Windows, each is a directory with python.exe and Lib/site-packages/. To use a package with a particular python.exe, you must install into the corresponding site-packages.

一点背景知识:一个系统可以有多个 Python 安装。在 Windows 上,每个目录都是一个包含 python.exe 和 Lib/site-packages/ 的目录。要使用带有特定 python.exe 的包,您必须安装到相应的站点包中。

In your case, 'python' invokes 'C:\Program Files (x86)\Anaconda3\python.exe'. Do you have another python installation that you want to be working with?

在您的情况下,“python”调用“C:\Program Files (x86)\Anaconda3\python.exe”。你有另一个想要使用的 python 安装吗?

In any case, the current standard way to install packages on Windows is with pip. The best way to run it in the console is

无论如何,当前在 Windows 上安装软件包的标准方法是使用 pip。在控制台中运行它的最佳方法是

some/path> <some python> -m pip install package 

where <some python>is either pythonto invoke the default install or something else to get another install. Pip first goes to pypi.python.org to find the package. If the package contains C code, it may find an appropriate pre-built binary or try to compile locally, which requires the correct version of Visual C++ compiler.

where<some python>要么python是调用默认安装,要么是其他东西来获得另一个安装。Pip首先去pypi.python.org找包。如果包包含 C 代码,它可能会找到合适的预构建二进制文件或尝试在本地编译,这需要正确版本的 Visual C++ 编译器。

If pip does not find a pre-built binary for your install, I would do the following. For about 200 packages, unofficial binaries are available at http://www.lfd.uci.edu/~gohlke/pythonlibs/. The site has been up for up, and a livesave for Windows users, for at least a decade and I and many others have used it. Cristoph gives instructions on how to download a file and then use pip to install it.

如果 pip 没有为您的安装找到预构建的二进制文件,我将执行以下操作。对于大约 200 个软件包,可以在http://www.lfd.uci.edu/~gohlke/pythonlibs/上找到非官方二进制文件。该网站已经正常运行,并为 Windows 用户提供了一个救命稻草,至少十年以来,我和许多其他人都使用过它。Cristoph 提供了有关如何下载文件然后使用 pip 安装它的说明。

回答by polonius11

This is all great feedback - I installed via the conda. And, I am using Spyder over the ILDE environment. Please the below from CMD.

这都是很好的反馈——我是通过 conda 安装的。而且,我在 ILDE 环境中使用 Spyder。请从CMD下面。

Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved.

Microsoft Windows [版本 6.1.7601] 版权所有 (c) 2009 Microsoft Corporation。版权所有。

C:\Windows\system32>conda install pyodbc Using Anaconda Cloud api site https://api.anaconda.orgFetching package metadata: .... Solving package specifications: .........

C:\Windows\system32>conda install pyodbc Using Anaconda Cloud api site https://api.anaconda.orgFetching package metadata: .... Solving package specification: ...

Package plan for installation in environment C:\Users\Hal\Anaconda3:

C:\Users\Hal\Anaconda3 环境安装包方案:

The following packages will be downloaded:

将下载以下软件包:

package                    |            build
---------------------------|-----------------
conda-env-2.6.0            |                0          498 B
python-3.5.2               |                0        30.3 MB
pyodbc-3.0.10              |           py35_1          48 KB
ruamel_yaml-0.11.14        |           py35_0         217 KB
conda-4.2.9                |           py35_0         428 KB
------------------------------------------------------------
                                       Total:        31.0 MB

The following NEW packages will be INSTALLED:

将安装以下新软件包:

pyodbc:      3.0.10-py35_1
ruamel_yaml: 0.11.14-py35_0

The following packages will be UPDATED:

以下软件包将被更新:

conda:       4.0.5-py35_0 --> 4.2.9-py35_0
conda-env:   2.4.5-py35_0 --> 2.6.0-0
python:      3.5.1-4      --> 3.5.2-0

Proceed ([y]/n)? y

继续 ([y]/n)?是

Fetching packages ... conda-env-2.6. 100% |###############################| Time: 0:00:00 0.00 B/s python-3.5.2-0 100% |###############################| Time: 0:00:20 1.56 MB/s pyodbc-3.0.10- 100% |###############################| Time: 0:00:00 788.82 kB/s ruamel_yaml-0. 100% |###############################| Time: 0:00:00 837.06 kB/s conda-4.2.9-py 100% |###############################| Time: 0:00:00 969.21 kB/s Extracting packages ... [ COMPLETE ]|##################################################| 100% Unlinking packages ... [ COMPLETE ]|##################################################| 100% Linking packages ... [ COMPLETE ]|##################################################| 100%

正在获取包... conda-env-2.6。100% |#############################| 时间:0:00:00 0.00 B/s python-3.5.2-0 100% |########################## ##| 时间:0:00:20 1.56 MB/s pyodbc-3.0.10- 100% |########################### #| 时间:0:00:00 788.82 kB/s ruamel_yaml-0。100% |#############################| 时间:0:00:00 837.06 kB/s conda-4.2.9-py 100% |########################## ##| 时间:0:00:00 969.21 kB/s 提取包... [完成]|############################ ####################| 100% 取消链接包... [完成]|#################################### ############| 100% 链接包... [完成]|#################################### ############| 100%

C:\Windows\system32>

C:\Windows\system32>