pyenv

pyenv is a popular command-line tool that helps Python developers manage multiple Python versions efficiently. If you work on various Python projects, each requiring a different version of Python, pyenv keeps your workflow smooth by allowing you to install, switch, and manage Python versions effortlessly. https://github.com/pyenv/pyenv To install, run Edit ~/.profile add at the end of the file Install build dependency on Ubunutu, run For other operating systems, see https://github.com/pyenv/pyenv/wiki#suggested-build-environment … Read more

Serve a Django application using Gunicorn

Create systemd service file vi /usr/lib/systemd/system/backend.service Add [Unit] Description=Gunicorn instance to serve Django Application After=network.target [Service] User=www-data Group=www-data Environment=”APP=app” WorkingDirectory=/path/to/app/backend Environment=”PATH=/path/to/app/backend/venv/bin” ExecStart=/path/to/app/backend/venv/bin/gunicorn -w 3 –timeout 120 –bind 0.0.0.0:8080 backend.wsgi [Install] WantedBy=multi-user.target On the above, you need to replace “/path/to/app/backend” with the path to your application. In backend.wsgi, backend is the application name here, change it … Read more

ModuleNotFoundError: No module named ‘MySQLdb’

When running migration for a Django application with “python manage.py migrate”, I got the following error message ModuleNotFoundError: No module named ‘MySQLdb’ To fix install pip install mysqlclient This will require MySQL development package. On the Ubuntu server running MariaDB, I installed packaged libmariadb-dev sudo apt install libmariadb-dev Back to Errors

How to install Python 3.10 on CentOS 7

First, install the dependency yum install -y wget zlib-devel yum groupinstall -y “Development tools” Install OpenSSL as the openssl-devel package provided by CentOS is old version. Install OpenSSL from source with cd /usr/local/src wget https://www.openssl.org/source/openssl-1.1.1g.tar.gz tar xvf openssl-1.1.1g.tar.gz cd openssl-1.1.1g ./config –prefix=/usr/serverok/openssl –openssldir=/usr/serverok/openssl no-ssl2 make make install Run following commands export PATH=/usr/serverok/openssl/bin:$PATH export LD_LIBRARY_PATH=/usr/serverok/openssl/lib export … Read more

ModuleNotFoundError: No module named ‘PIL’

When running a python application, I got the error message ModuleNotFoundError: No module named ‘PIL’ (venv) boby@sok-01:~/work/powder (master)$ python main.py Traceback (most recent call last): File “main.py”, line 6, in from extras import * File “/home/boby/work/powder/extras.py”, line 2, in from PIL import Image, ImageDraw, ImageFont ModuleNotFoundError: No module named ‘PIL’ (venv) boby@sok-01:~/work/powder (master)$ To fix … Read more

This version of ChromeDriver only supports Chrome version

When running a python application, I get the error message (venv) boby@sok-01:~/work/powder (master)$ python main.py 59 seconds remaining Process Process-1: Traceback (most recent call last): File “/usr/lib/python3.8/multiprocessing/process.py”, line 315, in _bootstrap self.run() File “/usr/lib/python3.8/multiprocessing/process.py”, line 108, in run self._target(*self._args, **self._kwargs) File “main.py”, line 51, in main driver = webdriver.Chrome( File “/home/boby/work/powder/venv/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py”, line 69, in __init__ … Read more

OSError: mysql_config not found

When installing the python mysqlclient module with pip, I got the error “OSError: mysql_config not found”. (venv) root@sok:~# pip install mysqlclient Collecting mysqlclient Downloading mysqlclient-2.1.0.tar.gz (87 kB) |████████████████████████████████| 87 kB 1.2 MB/s ERROR: Command errored out with exit status 1: command: /root/venv/bin/python3 -c ‘import sys, setuptools, tokenize; sys.argv[0] = ‘”‘”‘/tmp/pip-install-r5qp0a97/mysqlclient/setup.py’”‘”‘; __file__=’”‘”‘/tmp/pip-install-r5qp0a97/mysqlclient/setup.py’”‘”‘;f=getattr(tokenize, ‘”‘”‘open’”‘”‘, open)(__file__);code=f.read().replace(‘”‘”‘\r\n’”‘”‘, ‘”‘”‘\n’”‘”‘);f.close();exec(compile(code, __file__, … Read more

Uvicorn

Uvicorn is a lightning-fast ASGI server used to serve Python ASGI frameworks like FastAPI, Django Channels, Quart, BlackSheep, etc… https://www.uvicorn.org To install Uvicorn, run To run, you can use See Python

Flask Python framework

Flask is a Python framework. You can find more info at the official website. https://flask.palletsprojects.com/ How to start a Flask application? To start flask application, run python app.py How to run flask application on port 80 To run flask application on port 80, use command flask run –host 0.0.0.0 –port 80 Or edit app.py, use … Read more

Python mechanize HTTP Error 403 request disallowed by robots.txt

When running following python script i get error “HTTP Error 403 request disallowed by robots.txt” from mechanize import Browser a = [‘https://google.com’, ‘https://serverok.in’, ‘https://msn.com’] br = Browser() for x in range(len(a)): br.open(a[x]) print(“Website title: “) print(br.title()) print(“\n”) To fix this, find br = Browser() Add below br.set_handle_robots(False) br.addheaders = [(‘User-agent’, ‘Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 … Read more

error: Python.h: No such file or directory

When install dlib python module, i get error ERROR: Failed building wheel for dlib fatal error: Python.h: No such file or directory This is because missing python3-dev package. To fix, install apt install python3-dev If you are using python virtualenv, you will need to recreate the virtualenv after installing dev package. virtualenv -p /usr/bin/python3 venv