Python 错误:没有名为“fcntl”的模块

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

Error: No module named 'fcntl'

pythonwindowspython-3.xmodulecompiler-errors

提问by yome

I get the following error:

我收到以下错误:

Traceback (most recent call last):
  File "C:/Users/aaaa/Desktop/ttttttt.py", line 5, in <module>
   import reload
  File "C:\Users\aaa\AppData\Local\Programs\Python\Python36\lib\site-
packages\reload.py", line 3, in <module>
    import sys, time, re, os, signal, fcntl
ModuleNotFoundError: No module named 'fcntl'

So I did a pip install, which also gets an error.

所以我做了一个pip安装,它也得到了一个错误。

    C:\Users\aaaa>pip install fcntl
    Collecting fcntl
      Could not find a version that satisfies the requirement fcntl (from versions: )
No matching distribution found for fcntl

Search results cPython, hacking, routing and many other words are coming out.

搜索结果cPython、hacking、routing等很多词都出来了。

It's a tough answer for beginners, so I want to get a more detailed solution.

对于初学者来说,这是一个艰难的答案,所以我想得到一个更详细的解决方案。

How should I solve it?

我该如何解决?

#py3
import time
from selenium import webdriver
import codecs
import sys
import reload
import re
import fcntl
import os
import signal

回答by duskwuff -inactive-

The fcntlmodule is not available on Windows. The functionality it exposes does not exist on that platform.

fcntl模块在 Windows 上不可用。它公开的功能在该平台上不存在。

If you're trying to lock a file, there are some other Python modules available which provide that functionality. One I've seen referenced in other answers is portalocker.

如果您尝试锁定文件,则可以使用其他一些 Python 模块来提供该功能。我在其他答案中看到的一个是portalocker.

回答by Victor Hartong

What you can do is install importlib with the usual:

您可以做的是使用通常的方式安装 importlib:

pip install importlib

From there use the following:

从那里使用以下内容:

from importlib import reload

Note that you will need to load your imports as 'modules':

请注意,您需要将导入加载为“模块”:

from petshop import parrot as parrot