Reputation: 1153
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
Upvotes: 84
Views: 258923
Reputation: 107
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
Upvotes: 0
Reputation: 167
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.
Upvotes: 1
Reputation: 70008
Got this error on Windows as well: ModuleNotFoundError: No module named 'fcntl'
Used the recommended portalocker
package from this answer: https://stackoverflow.com/a/45228507/3850405
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)
Upvotes: 1
Reputation: 531
"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)
If you're using Windows, you can use Waitress as an alternative to Gunicorn.
server.py
file with the following content:from waitress import serve
from yourdjangoproject.wsgi import application
if __name__ == '__main__':
serve(application, port='8000')
python server.py
Upvotes: 8
Reputation: 591
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.
Upvotes: 53
Reputation: 47
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
Upvotes: 2
Reputation: 25
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
Upvotes: -4
Reputation:
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
.
Upvotes: 71