You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importosimportos.pathimportsysimportsitesite.addsitedir('/var/www/html/env/lib/python2.7/site-packages')
sys.path.append('/var/www/html')
sys.path.append('/var/www/html/main')
os.environ['PYTHON_EGG_CACHE'] ='/var/www/html/egg_cache'os.environ['DJANGO_SETTINGS_MODULE'] ='main.settings'# for Django <= 1.6# import django.core.handlers.wsgi# application = django.core.handlers.wsgi.WSGIHandler()# for Django 1.8 and 1.7fromdjango.core.wsgiimportget_wsgi_applicationapplication=get_wsgi_application()
[optinally] copy the same code to another code.
cp django.wsgi secondweb.wsgi
Step 2:
move to this directory
cd /etc/apache2/sites-available/
and create new configure file to run your site by apache2.
nano 000-default.conf
write this code:
<VirtualHost *:80>
# .. After Apache2 lines and comments .. #
<Directory /var/www/html>
<Files django.wsgi>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess html python-path=/var/www/html:/var/www/html/env/lib/python2.7/site-packages
WSGIProcessGroup html
WSGIScriptAlias / /var/www/html/django.wsgi
WSGIPassAuthorization On
# important for subprocess.Popen() work
WSGIApplicationGroup %{GLOBAL}
Alias /static /var/www/html/static/
<Directory /var/www/html/static>
Require all granted
</Directory>
#Alias /media /var/www/html/media/
</VirtualHost>
Python is a popular programming language often used to write scripts for operating systems. It’s versatile enough for use in web development and app design.
Prerequisites
A system running Ubuntu 18.04 or Ubuntu 20.04
A user account with sudo privileges
Access to a terminal window/command-line (Ctrl–Alt–T)
Make sure your environment is configured to use Python 3.8
Option 1: Install Python 3 Using apt (Easier)
This process uses the apt package manager to install Python. There are fewer steps, but it’s dependent on a third party hosting software updates. You may not see new releases as quickly on a third-party repository.
python --version
Step 1: Update and Refresh Repository Lists
Open a terminal window, and enter the following:
sudo apt update
Step 2: Install Supporting Software
The software-properties-common package gives you better control over your package manager by letting you add PPA (Personal Package Archive) repositories. Install the supporting software with the command:
sudo apt install software-properties-common
Step 3: Add Deadsnakes PPA
Deadsnakes is a PPA with newer releases than the default Ubuntu repositories. Add the PPA by entering the following:
sudo add-apt-repository ppa:deadsnakes/ppa
The system will prompt you to press enter to continue. Do so, and allow it to finish. Refresh the package lists again:
sudo apt update
Step 4: Install Python 3
Now you can start the installation of Python 3.6 with the command:
Option 2: Install Python 3.6 From Source Code (Latest Version)
Use this process to download and compile the source code from the developer. It’s a bit more complicated, but the trade-off is accessing a newer release of Python.
Step 1: Update Local Repositories
To update local repositories, use the command:
sudo apt update
Step 2: Install Supporting Software
Compiling a package from source code requires additional software.
Enter the following to install the required packages for Python:
Step 3: Download the Latest Version of Python Source Code
To download the newest release of Python Source Code, navigate to the /tmp directory and use the wget command:
cd /tmp
wget https://www.python.org/ftp/python/3.6.15/Python-3.6.15.tgz
Step 4: Extract Compressed Files
Next, you need to extract the tgz file you downloaded, with the command:
tar -xzvf Python-3.6.15.tgz
Step 5: Test System and Optimize Python
Before you install the software, make sure you test the system and optimize Python.
The ./configure command evaluates and prepares Python to install on your system. Using the ––optimization option speeds code execution by 10-20%.
cd Python-3.6.15/
./configure --enable-optimizations --enable-shared --with-ensurepip=install
make -j $(nproc)
This step can take up to 30 minutes to complete.
Step 6: Install a Second Instance of Python (recommended)
To create a second installation of Python 3.6.15, in addition to your current Python installation, enter the following:
sudo make altinstall
It is recommended that you use the altinstall method. Your Ubuntu system may have software packages dependent on Python 2.x.
Overwrite Default Python Installation (Option)
To install Python 3.6.15 over the top of your existing Python, enter the following:
sudo make install
Allow the process to complete.
Step 7: Verify Python Version
Enter the following:
python3 ––version
Using Different Versions of Python
If you used the altinstall method, you have two different versions of Python on your system at the same time. Each installation uses a different command.
Use the python command to run commands for any older Python 2.x version on your system. For example:
python ––version
To run a command using the newer version, use python3. For example:
python3 ––version
It is possible to have multiple major (3.x or 2.x) versions of Python on your system. If you have Python 3.6.x and Python 3.8.x both installed, use the second digit to specify which version you want to use:
python3.6 ––version
python3.8 ––version
Conclusion
You should now have a working installation of Python 3 on your Ubuntu system.