Python 在pycharm中安装csv包
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41061824/
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
install csv package in pycharm
提问by criticalth
I have a problem with installing csv package in pycharm (running under python 3.5.2)
我在pycharm中安装csv包时遇到问题(在python 3.5.2下运行)
When I try to install it I get an error saying
当我尝试安装它时,我收到一条错误消息
Executed command:
pip install --user csv
执行的命令:
pip install --user csv
Error occurred: Non-zero exit code (1)
发生错误:非零退出代码 (1)
Could not find a version that satisfies the requirement csv (from versions: ) No matching distribution found for csv
找不到满足 csv 要求的版本(来自版本:)找不到与 csv 匹配的发行版
I updated the pip package to version 9.0.1 but still nothing.
我将 pip 包更新到 9.0.1 版,但仍然没有。
When I run the following code:
当我运行以下代码时:
import csv
f = open('fl.csv')
csv_f = csv.reader(f)
f.close()
I get this error:
我收到此错误:
csv_f = csv.reader(f) AttributeError: module 'csv' has no attribute 'reader'
csv_f = csv.reader(f) AttributeError: 模块 'csv' 没有属性 'reader'
I thought it was because I could not install the "csv package"
我以为是因为我无法安装“csv包”
also I tried running:
我也试过运行:
import csv
print(dir(csv))
and the print result is:
打印结果是:
['doc', 'loader', 'name', 'package', 'path', 'spec']
[' doc',' loader',' name',' package',' path',' spec']
A lot of methods including csv.reader are missing
缺少包括 csv.reader 在内的很多方法
This is pretty much all the useful information up until comment #29
这几乎是所有有用的信息,直到评论 #29
回答by Venkataraman K S
You can't pip install csv
because the csv module is included in the Python installation.
你不能,pip install csv
因为 csv 模块包含在 Python 安装中。
You can directly use :
您可以直接使用:
import csv
in your program
在你的程序中
Thanks
谢谢
回答by MMF
The problem is that you have another file in your directory called csv.py
. And in this file you do not have a reader
function.
问题是您的目录中有另一个名为csv.py
. 在这个文件中你没有一个reader
函数。
Change its name to my_csv.py
将其名称更改为 my_csv.py
回答by jestadi
- 'csv' is an in-built package. So you dont have to install it again in Pycharm.
- When you try to import csv, make sure that you dont have any file(created by you) named as 'csv.py' in your project folder(or Python Path Variable folders) because of this you are not actually importing 'csv' package.
- 'csv' 是一个内置包。所以你不必在 Pycharm 中再次安装它。
- 当您尝试导入 csv 时,请确保您的项目文件夹(或 Python 路径变量文件夹)中没有任何名为 'csv.py' 的文件(由您创建),因为您实际上并未导入 'csv' 包.
回答by Mehrnoosh Nobakht
for python 3, you should run this command:
对于 python 3,你应该运行这个命令:
pip install python-csv
回答by newborngeek
You should go to Terminal in PyCharm and type:
您应该转到 PyCharm 中的终端并输入:
pip3 install python-csv