• 【python初级】No module named ‘fcntl‘


    【python初级】No module named 'fcntl'

    1、背景

    windows10 操作系统;
    gunicorn:20.1.0

    在安装gunicorn之后,导入from gunicorn.app.wsgiapp import run报错。

    pip 安装 gunicorn,如下:

    C:\Users\Administrator>pip install gunicorn
    Collecting gunicorn
      Downloading gunicorn-20.1.0-py3-none-any.whl (79 kB)
         ---------------------------------------- 79.5/79.5 kB 1.5 MB/s eta 0:00:00
    Requirement already satisfied: setuptools>=3.0 in e:\e01_pykaifa\e01_01_python3\install_python3.8.8\lib\site-packages (from gunicorn) (49.2.1)
    Installing collected packages: gunicorn
    Successfully installed gunicorn-20.1.0
    
    C:\Users\Administrator>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    导入from gunicorn.app.wsgiapp import run报错,如下:

    C:\Users\Administrator>python
    Python 3.8.8 (tags/v3.8.8:024d805, Feb 19 2021, 13:18:16) [MSC v.1928 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from gunicorn.app.wsgiapp import run
    Traceback (most recent call last):
      File "", line 1, in <module>
      File "E:\E01_PyKaiFa\E01_01_Python3\install_python3.8.8\lib\site-packages\gunicorn\app\wsgiapp.py", line 9, in <module>
        from gunicorn.app.base import Application
      File "E:\E01_PyKaiFa\E01_01_Python3\install_python3.8.8\lib\site-packages\gunicorn\app\base.py", line 11, in <module>
        from gunicorn import util
      File "E:\E01_PyKaiFa\E01_01_Python3\install_python3.8.8\lib\site-packages\gunicorn\util.py", line 8, in <module>
        import fcntl
    ModuleNotFoundError: No module named 'fcntl'
    >>>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    2、解决办法

    解决办法:在python路径下的Lib中新建一个fcntl.py文件内容如下:

    # fcntl.py
    
    LOCK_UN=8
    F_GETFD=1
    FD_CLOEXEC=1
    F_SETFD=2
    
    def fcntl(fd, op, arg=0):
        return 0
    
    def ioctl(fd, op, arg=0, mutable_flag=True):
        if mutable_flag:
            return 0
        else:
            return ""
    
    def flock(fd, op):
        return
    
    def lockf(fd, operation, length=0, start=0, whence=0):
        return
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21

    博主python安装目录:

    E:\E01_PyKaiFa\E01_01_Python3\install_python3.8.8
    
    • 1

    3、关于Gunicorn

    这只解决了No module named ‘fcntl’,再次运行又会报新的错误:

    C:\Users\Administrator>python
    Python 3.8.8 (tags/v3.8.8:024d805, Feb 19 2021, 13:18:16) [MSC v.1928 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from gunicorn.app.wsgiapp import run
    Traceback (most recent call last):
      File "", line 1, in <module>
      File "E:\E01_PyKaiFa\E01_01_Python3\install_python3.8.8\lib\site-packages\gunicorn\app\wsgiapp.py", line 9, in <module>
        from gunicorn.app.base import Application
      File "E:\E01_PyKaiFa\E01_01_Python3\install_python3.8.8\lib\site-packages\gunicorn\app\base.py", line 11, in <module>
        from gunicorn import util
      File "E:\E01_PyKaiFa\E01_01_Python3\install_python3.8.8\lib\site-packages\gunicorn\util.py", line 15, in <module>
        import pwd
    ModuleNotFoundError: No module named 'pwd'
    >>>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    为什么呢?
    因为目前为止,Gunicorn还不能在Windows上运行。

    但是已经有Windows支持的计划了,相信未来能很好的支持到Windows系统。
    现在计划添加Windows支持。https://github.com/benoitc/gunicorn/issues/524

    Gunicorn官网:
    https://docs.gunicorn.org/en/stable/index.html
    在这里插入图片描述

  • 相关阅读:
    异步调用中的问题
    springboot+springSecurity+jwt实现登录认证后令牌授权
    C++初阶--C++入门(2)
    Android 13.0 framework中开机启动的过程中监听launcher是否启动完成的源码分析
    Python 线性查找
    LeetCode 每日一题 2022/11/14-2022/11/20
    06【MyBatis的配置文件】
    elementUI-表单-校验
    token_to_image
    如何从零开始解读什么叫产品经理
  • 原文地址:https://blog.csdn.net/jn10010537/article/details/126314979