【问题标题】:Error: No module named 'fcntl'错误:没有名为“fcntl”的模块
【发布时间】:2017-12-26 23:00:22
【问题描述】:

我收到以下错误:

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'

所以我做了一个 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

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

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

我该如何解决?

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

【问题讨论】:

    标签: python windows python-3.x module compiler-errors


    【解决方案1】:

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

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

    【讨论】:

    • 感谢您的回复。我已经下载了上述内容,但现在我无法弄清楚如何使用它。
    • 我是否正确理解不能以这种“语言”从 Windows 上的管道进行非阻塞读取?
    【解决方案2】:

    你可以用通常的方式安装 importlib:

    pip install importlib
    

    从那里使用以下内容:

    from importlib import reload
    

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

    from petshop import parrot as parrot
    

    【讨论】:

    • 我没有关注这个答案与问题的关系。 importlib.reload() 可用于重新加载模块。用户的问题与“fcntl 在 Windows 上不存在”有关。你如何重新加载一个甚至因为它不存在而没有安装的模块?
    【解决方案3】:

    我从这个网站https://pypi.org/project/micropython-fcntl/#files 获得了一些信息并安装如下解决了问题:

    pip install micropython-fcntl
    

    【讨论】:

    • ERROR: File "setup.py" or "setup.cfg" not found for legacy project micropython-fcntl from https://files.pythonhosted.org/packages/c9/65/f233834bc23621c1a8da644bd1d70cbe5c344bd2dd2b9d424f1f116363ec/micropython-fcntl-0.0.4.tar.gz#sha256=6ce976b79c16084485894e4284c54263c0cc775cf6b4a6fd3bf1d83f29ddf6a1. :(
    猜你喜欢
    • 1970-01-01
    • 2020-10-28
    • 2020-02-12
    • 2019-01-17
    • 2014-12-25
    • 2018-04-29
    • 2011-06-26
    • 2017-01-07
    • 2013-06-28
    相关资源
    最近更新 更多