简体   繁体   English

尽管已安装,但未找到模块文件 I/O

[英]Module File I/O is not found despite being installed

I'm trying to access some data from a public source, however I have trouble getting the module fileio to work despite installing it with pip.我正在尝试从公共来源访问一些数据,但是尽管使用 pip 安装了模块 fileio,但我仍然无法使其正常工作。 Here's my code:这是我的代码:

from fileio import read
import gzip
odffn = 'test-data/Level1_IC59_data_Run00115150_Part00000000.odf.gz'
f = gzip.open(odffn)
ev = read(f)
hit_dist = list()

while ev :
    # do some analysis with the event
    hit_dist.append(len(ev.hits))
    # get the next event
    ev = read(f)

import pylab
pylab.hist(hit_dist,30,range=(0,1000), log=True, histtype='step')
pylab.title('IceCube Hit Distribution')
pylab.xlabel('nhit')
pylab.savefig('nhits.png')

And I get the following error:我收到以下错误:

from fileio import read
ModuleNotFoundError: No module named 'fileio'

However, I already checked using the pip installer,但是,我已经使用 pip 安装程序进行了检查,

python -m pip install fileio

And I get the module is already installed.我得到模块已经安装。 I don't think it's a problem with the PATH since it works well with all the other models (ie numpy), so I'm not really sure what could be the problem.我不认为 PATH 有问题,因为它适用于所有其他模型(即 numpy),所以我不确定可能是什么问题。 I appreciate in advance any insight.我提前感谢任何见解。

I looked in pip for fileio and from what I can see, this doesn't appear to be a legitimate package.我在 pip 中查找了fileio ,从我所见,这似乎不是一个合法的包。 When installed from pip it doesn't install any importable Python modules or packages.从 pip 安装时,它不会安装任何可导入的 Python 模块或包。 All it does it create a skeleton directory under site-packages .它所做的一切都是在site-packages下创建一个骨架目录。

I think you should step back and re-evaluate what this code is doing:我认为你应该退后一步,重新评估这段代码在做什么:

from fileio import read
import gzip
odffn = 'test-data/Level1_IC59_data_Run00115150_Part00000000.odf.gz'
f = gzip.open(odffn)
ev = read(f)
hit_dist = list()

This seems fine (ignoring the import from fileio), up until the line: ev = read(f) .这似乎很好(忽略从 fileio 导入),直到行: ev = read(f) What is the purpose of using this function to read the file object that gzip returns?使用这个函数读取gzip返回的文件对象的目的是什么? That object has its own set of read methods that should be able to do the job:该对象有自己的一组读取方法,应该能够完成这项工作:

import gzip
odffn = 'test-data/Level1_IC59_data_Run00115150_Part00000000.odf.gz'
f = gzip.open(odffn)
lines = f.readlines()

Assuming this is a text file, that should read the whole thing into a list of strings, one per line.假设这是一个文本文件,它应该将整个内容读入一个字符串列表,每行一个。 You can also buffer it:你也可以缓冲它:

buf_size = 100
buf = f.read(buf_size)
while buf:
    <do something with 1-100 characters of input>
    buf = f.read(buf_size)

or buffer whole lines:或缓冲整行:

line_buf = f.readline()
while line_buf:
    <do something with a line of input>
    line_buf = f.readline()

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

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