简体   繁体   English

在pycharm中安装csv包

[英]install csv package in pycharm

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

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谢谢

  1. 'csv' is an in-built package. 'csv' 是一个内置包。 So you dont have to install it again in Pycharm.所以你不必在 Pycharm 中再次安装它。
  2. 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 时,请确保您的项目文件夹(或 Python 路径变量文件夹)中没有任何名为 'csv.py' 的文件由您创建),因为您实际上并未导入 'csv' 包.

The problem is that you have another file in your directory called csv.py .问题是您的目录中有另一个名为csv.py文件。 And in this file you do not have a reader function.在这个文件中你没有reader功能。

Change its name to my_csv.py将其名称更改为my_csv.py

对于 python 3,你应该运行这个命令:

pip install python-csv

您应该转到 PyCharm 中的终端并输入:

pip3 install python-csv

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

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