Error: No module named 'fcntl'
Asked Answered
L

8

80

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.

    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.

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
Lammergeier answered 21/7, 2017 at 3:16 Comment(2)
What did you do to get it working on Windows?Berte
Use virtualenv. Create virtual env on your windows system using "python -m venv myenv"Dinka
O
68

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

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.

Oliveolivegreen answered 21/7, 2017 at 3:31 Comment(4)
thank you for the reply. I have downloaded the above, but now I am having trouble figuring out how to use it.Lammergeier
Do I understand it properly that I cannot do a non-blocking read from a pipe on Windows in this "language"?Chenay
@User149341 And after what we have to do?Bucolic
Well like the others, this module is not available on Windows, but how can that mentioned package help?Berte
G
46

I got the same error when trying to run my flask app using gunicorn.

gunicorn --bind 127.0.0.1:5000 predict:app

The issue is that 'fcntl' is not available on windows. The alternative that can be used, as suggested by Alexey Grigorov in Ml bookcamp, is the 'waitress' package.

pip install waitress

Then write in the command prompt the following command.

waitress-serve --listen=127.0.0.1:5000 predict:app

For those still looking for the answer.

Governor answered 25/8, 2022 at 13:50 Comment(1)
Worked for me on Windows 10 thanksLisandra
B
7

"gunicorn" is not intended for use on Windows. To run the program, consider using Docker or a virtual machine (VM).

For further insights and discussions regarding the compatibility issues with Windows, you can refer to the GitHub discussions:

Again note gunicorn is not intended for Windows.

For Django project deployment(similar is procedure if you want to use for deployment in other python framework)

Running on Windows

If you're using Windows, you can use Waitress as an alternative to Gunicorn.

  1. Create a server.py file with the following content:
from waitress import serve
from yourdjangoproject.wsgi import application

if __name__ == '__main__':
    serve(application, port='8000')
  1. Run the server using the command:
python server.py
Buzzell answered 15/9, 2023 at 14:34 Comment(0)
M
2

I got some info from this website https://pypi.org/project/micropython-fcntl/#files and installed as follows which solved the problem:

pip install micropython-fcntl
Marya answered 12/5, 2021 at 1:20 Comment(4)
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. :(Procopius
this is not working as @Procopius said :(Am‚lie
ERROR: micropython-fcntl from https://files.pythonhosted.org/packages/c9/65/f233834bc23621c1a8da644bd1d70cbe5c344bd2dd2b9d424f1f116363ec/micropython-fcntl-0.0.4.tar.gz does not appear to be a Python project: neither 'setup.py' nor 'pyproject.toml' found.Under
I am getting the same error as above :(Achromatin
G
1

I don't know the context of the python application or what kind of app.

Tip for Django Developers

Anyone trying to run Django application using gunicorn using this command on windows os:

gunicorn project_name.wsgi:application

You will encounter similar error:

ModuleNotFoundError: No module named 'fcntl'

Since docker runs on window but internally runs linux container. Just dockerize your Django project to test gunicorn locally or migrate to linux. gunicorn is meant to run on linux servers.

Gerome answered 11/5 at 21:35 Comment(0)
D
0

Got this error on Windows as well: ModuleNotFoundError: No module named 'fcntl'

Used the recommended portalocker package from this answer: https://mcmap.net/q/1173044/-error-no-module-named-39-fcntl-39

This is a good guide on how to switch from fcntl to portalocker:

https://github.com/jamesls/flask-shelve/issues/2#issuecomment-190817196

My old code:

import fcntl

with open(lockfile, "w") as outputfile:
    fcntl.flock(outputfile.fileno(), fcntl.LOCK_EX)

fcntl.flock(outputfile.fileno(), fcntl.LOCK_UN)

Replaced working code with portalocker:

import portalocker

with open(lockfile, "wb") as outputfile:
    portalocker.lock(outputfile, portalocker.LOCK_EX)

portalocker.unlock(outputfile)
Dotation answered 8/5 at 10:14 Comment(0)
D
0

I have been through this same problem. Then found a solution using virtualenv.

Create a virtualenv on your windows system using below command

python -m venv myenv

Activate the virtualenv.

Then create your project and install that package there.

Good luck

Dinka answered 14/8 at 8:54 Comment(0)
R
-4

What you can do is install importlib with the usual:

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
Radiobroadcast answered 5/12, 2019 at 14:24 Comment(2)
I'm not following how this answer relates to the question. importlib.reload() can be used to reload a module. The user's question is related to "fcntl doesn't exist on windows". How do you reload a module that isn't even isntalled because it doesn't exist?Odetteodeum
Besides answering the wrong question, importlib needs no pip install in anything released in the last decade (this answer was already obsolete when posted).Rancher

© 2022 - 2024 — McMap. All rights reserved.