Python 没有这样的文件或目录

Python 没有这样的文件或目录,python,python-3.x,bioinformatics,biopython,Python,Python 3.x,Bioinformatics,Biopython,当我尝试在Biopython做任何事情时,我总是收到这个错误。我不知道如何改变Biopython的路径,因为python和Biopython在同一条路径上。我不知道我还需要做什么 Python 3.8.5 (v3.8.5:580fbb018f, Jul 20 2020, 12:11:27) [Clang 6.0 (clang-600.0.57)] on darwin Type "help", "copyright", "

当我尝试在Biopython做任何事情时,我总是收到这个错误。我不知道如何改变Biopython的路径,因为python和Biopython在同一条路径上。我不知道我还需要做什么

    Python 3.8.5 (v3.8.5:580fbb018f, Jul 20 2020, 12:11:27) 
    [Clang 6.0 (clang-600.0.57)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from Bio import SeqIO
    >>> 
    >>> user_input = input("please input an Accession Number: ")
    please input an Accession Number: NC_005816.gb

    >>> file = SeqIO.read(user_input, "genbank")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-       packages/Bio/SeqIO/__init__.py", line 654, in read
        iterator = parse(handle, format, alphabet)
      File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-  packages/Bio/SeqIO/__init__.py", line 607, in parse
        return iterator_generator(handle)
      File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site- packages/Bio/SeqIO/InsdcIO.py", line 93, in __init__
        super().__init__(source, mode="t", fmt="GenBank")
      File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/Bio/SeqIO/Interfaces.py", line 47, in __init__
        self.stream = open(source, "r" + mode)
    FileNotFoundError: [Errno 2] No such file or directory: 'NC_005816.gb'

Python 3.8.5(v3.8.5:580fbb018f,2020年7月20日,12:11:27)
关于达尔文的[Clang 6.0(Clang-600.0.57)]
有关详细信息,请键入“帮助”、“版权”、“信用证”或“许可证”。
>>>来自Bio import SeqIO
>>> 
>>>用户输入=输入(“请输入登录号:”)
请输入登录号:NC_005816.gb
>>>文件=SeqIO.read(用户输入,“genbank”)
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
文件“/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/Bio/SeqIO/_init__.py”,第654行,已读
迭代器=解析(句柄、格式、字母表)
文件“/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/Bio/SeqIO/_init__.py”,第607行,在parse中
返回迭代器\生成器(句柄)
文件“/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/Bio/SeqIO/InsdcIO.py”,第93行,在__
super()
文件“/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site packages/Bio/SeqIO/Interfaces.py”,第47行,在__
self.stream=开放(源代码,“r”+模式)
FileNotFoundError:[Errno 2]没有这样的文件或目录:“NC\u 005816.gb”

NC_005816.gb
不在您在中调用的
python
目录中。 试着做

导入操作系统
chdir(“path/to/folder/of/NC_005816.gb”)
...  # 你的代码在这里
更改当前工作目录。 但是,如果需要根据用户输入动态更改,则可以请求文件的路径:

from pathlib import Path
from Bio import SeqIO
user_input = input("Enter the path to the accession number:")

if Path(user_input).expand_user().exists():
    file = SeqIO.read(user_input, "genbank")
else:
    print("Invalid input")

可以找到Python的pathlib文档

NC_005816。gb
不在您在中调用的
Python
目录中。尝试执行
导入操作系统;os.chdir(“path/to/NC_005816.gb”)
更改当前的工作目录为什么您认为这与BioPython有关?错误很明显。当前工作目录中没有这样的文件
NC_005816.gb
(这是您提供的输入),您是否试图在没有本地存储文件的情况下从登录中查找genbank文件?如果是,您需要
Bio.Entrez
那么我是否需要更改每个用户输入登录号的目录?@Chris您可以向用户询问登录号的路径谢谢您的帮助。登录号是SeqIO软件包的一部分。我不需要问路径正确吗?它是Genbank文件的标识符。