Install python on linux command line

How to download python from command-line? [closed]

I’m on windows, but I’m using a putty shell to connect to a linux machine, and want to install python 2.7. Can’t figure out how to do it. How can I download python from command line?

Do you have admin rights on the linux machine? And have you checked if it’s already there — many Linux distributions have Python there by default.

3 Answers 3

wget --no-check-certificate https://www.python.org/ftp/python/2.7.11/Python-2.7.11.tgz tar -xzf Python-2.7.11.tgz cd Python-2.7.11 

Now read the README file to figure out how to install, or do the following with no guarantees from me that it will be exactly what you need.

./configure make sudo make install 

For other versions and the most up to date download links:
http://www.python.org/getit/

Also add the path of new python in ‘PATH’ environment variable. Eg. if new python is in /root/python-2.7.4 then run «export PATH = $PATH:/root/python-2.7.4» to detech new python verison

wget —no-check-certificate python.org/ftp/python/2.7.6/Python-2.7.6.tgz works for me and rest as Andrew Clark said

apt-get install python2.7 will work on debian-like linuxes. The python website describes a whole bunch of other ways to get Python.

If you were to tell us which version of Linux you are using it would help. There are many flavours and they differ significantly in package management.

Well if you are getting into a linux machine you can use the package manager of that linux distro.

If you are using Ubuntu just use apt-get search python, check the list and do apt-get install python2.7 (not sure if python2.7 or python-2.7, check the list)

You could use yum in fedora and do the same.

if you want to install it on your windows machine i dont know any package manager, i would download the wget for windows, donwload the package from python.org and install it

Источник

How to Install Python on Linux?

Python Certification Course: Master the essentials

In this article, you will learn all about starting your journey with this Python tutorial by installing and interacting with Python for Linux. Follow the steps and start coding in no time!

Introduction

Rahul recently read an article on «what is Python?» and came across all the amazing things he can create and achieve using Python. Rahul is highly intrigued and wishes to start his Python journey immediately. This is no surprise, as Python is a widely-used, high-level programming language used across various disciplines.

Well, if this sounds anything like you, then you are at the right place! The first step to becoming a Pythoneer or a Pythonista, if you are a Linux user, is to know the answer to the question “How to Install Python on Linux and interact with it?”

Читайте также:  Прокси сервер linux web

Prerequisite to Install Python on Linux

You will need certain prerequisites to be met before you successfully know how to install Python on Linux. They are as follows-

  • A computer running on Debian / Fedora OS with a minimum of 2GB RAM (4GB Preferable) and 5GB of disk space
  • Also, you need sudo access on the system you want to install Python on Linux

sudo command: It allows you to temporarily elevate your current user account to have root privileges.

How to Check the Python Version on Linux?

Python comes preinstalled on most of the Linux distributions like Debian.

You can simply check the Python Version, which is already installed on your system, by running python -V or python —version command on your terminal.

Check Python Version on Linux

When Python is not already installed: The output will be something like this-

When Python is already Installed: The output will be something like this-

Python is already installed

Python x.x.x For example, Python 3.8.5-

Two Ways to Install Python on Linux

I. Install Python on Linux from Package Manager:

The following command could be used to install the latest version of Python on almost every Linux system.

Also, you can mention the particular version of Python you want to install, shown below :

Install Python on Linux from Package Manager

Type Y and press Enter to continue. The Package manager will download and install the Python for you.

Download Python from Package Manager

II. Build from source code

Before starting, please make sure that you have git , gcc , and make installed on your system.

Steps to be followed to Build Python from Source Code:

1. Get the Source code:

We can clone the latest Python source code from Python’s official GitHub repository using git to install Python on Linux.

Get Source Code in Python

2. Configure:

The configuration script comes with the source code that can be passed through many flags.

  • —prefix : Used to determine where the final built files go
  • —enable-optimizations — Enable Profile Guided Optimization (PGO) using PROFILE_TASK (disabled by default). Optimization takes a long time to configure, but the resulting python binary interpreter is 10% faster at executing Python code.
  • Navigate to the cpython directory where we have cloned Python source code-

Note: $HOME will contain the path to the current user’s home directory. You can check your home directory by using the echo command.

Add Command in Python

Your terminal will show something like this once the configuration is done —

Terminal in Python

  • Once the configuration is done, we are ready to start the build process.
  • Run the make tool to build the files, followed by the make install command to put the built files in the location specified by configure’s —prefix .
  • The final output of the make command will be something like this —

Build Command in Python

Output of Make Install in Python

Step by Step Guide to Install Python on Linux

  • Step 1 — Install Development Packages Required to Install Python on Linux-
    1. On Debian
    2. On Fedora
  • Step 2 — Download the Latest Version of Python
  • Step 3 — Extract the tar file to install Python on Linux
  • Step 4 — Configure the Script
  • Step 5 — Getting Through the steps to install Python on Linux and finishing installation
  • Step 6 — Verify the Installation
  • Step 7 — Create Virtual Environment(Optional)

1. Install Development Packages Required to install Python on Linux:

On Debian: Follow the below steps to install the development packages required to install Python on Linux (Debian system)-

    Ensure you have enabled the source packages in the sources list. You can do this by adding the location of the source packages, including URL, distribution name, and component name, to /etc/apt/sources.list . Take Ubuntu Bionic, for example:

Update Package Index in Python

Install the Python Build dependencies: You can install the build dependencies by running the below command on your Terminal.

Step 2- Download latest version of Python:

You can download the latest version of Python as tar file by visiting python.org.

Download latest version of python

Just click on the download button to download the tar file. Note: At the time of writing this article, the latest version of Python was 3.9.6.

Step 3- Extract the tar file to install Python on Linux:

Once the download is completed, open the Terminal and navigate to the Downloads directory.

Run the below tar command to extract the files-

Extract tar file in Python

In our case the name of the downloaded file is Python-3.9.6.tar.xz . So the command will be-

The above command will create a directory in the name of the file (without file extension). So the name of the directory will be Python-3.9.6 .

Step4- Configuring the Script:

Configuring script in python

Follow the Configure and Build steps of Build from source code.

Let’s create an alias for Python 3.9 so the version will not confuse us. An alias can be easily created by using alias commands like those given below.

Step 5- Getting Through the steps to install Python on Linux and finishing installation

In this step, you have to let the system do its thing and wait for it to install Python on Linux.

Step 6- Verify the installation:

You are so close to completing the installation of Python on Linux! Now, open any of your favorite code/text editors and add the below code.

Verify Installation in Python

Save the file with the .py extension. For example, helloworld.py .

Save File in Python

Open terminal inside the directory where you saved the .py file. And run the program file using the python command.

Output of python program

The output of the program-

Step 7- Create Virtual Environment(Optional) :

There are many ways to create a Python virtual environment after you have learnt how to install Python on Linux. Here we are going to see how to create a python virtual environment using the virtual environment package which comes with Python3.

You can create a Python virtual environment by just running the below command on your Terminal.

Create virtual environment

Replace test_env with the path where you want to store your virtual environment

Then verify the created virtual environment by using the ls command shown in the above picture.

You may get the output as shown in the picture below if the Python virtual environment is not installed already.

Verify python virtual environment

In this case, you can install the package by using the below command-

Install python 3 package

Press Y and Enter to continue the installation.

Continue Installation in Python

Now again, try to run the command to create the virtual environment.

The newly created virtual environment can be activated by using the source command-

Activate virtual environment

Here also replace the test_env with your virtual environment path.

Conclusion

  • You can now finally say you know how to install Python on Linux!
  • After reading this article, you should be able to Configure, Install and Run Python on a Linux system and be able to create a Python virtual environment.
  • Important things to remember while you install Python on Linux-
  • Be sure always to check the version you are installing and its compatibility with the Operating System installed on your system.
  • After setup is done, always verify if Python is successfully installed.

Read More:

Источник

Installing Python 3 on Linux¶

https://d33wubrfki0l68.cloudfront.net/02962eb19c0069740d16e67b5ba7c613238c8b9a/30ed2/_images/34435689480_2e6f358510_k_d.jpg

This document describes how to install Python 3.6 or 3.8 on Ubuntu Linux machines.

To see which version of Python 3 you have installed, open a command prompt and run

If you are using Ubuntu 16.10 or newer, then you can easily install Python 3.6 with the following commands:

$ sudo apt-get update $ sudo apt-get install python3.6

If you’re using another version of Ubuntu (e.g. the latest LTS release) or you want to use a more current Python, we recommend using the deadsnakes PPA to install Python 3.8:

$ sudo apt-get install software-properties-common $ sudo add-apt-repository ppa:deadsnakes/ppa $ sudo apt-get update $ sudo apt-get install python3.8

If you are using other Linux distribution, chances are you already have Python 3 pre-installed as well. If not, use your distribution’s package manager. For example on Fedora, you would use dnf :

Note that if the version of the python3 package is not recent enough for you, there may be ways of installing more recent versions as well, depending on you distribution. For example installing the python3.9 package on Fedora 32 to get Python 3.9. If you are a Fedora user, you might want to read about multiple Python versions available in Fedora.

Working with Python 3¶

At this point, you may have system Python 2.7 available as well.

This might launch the Python 2 interpreter.

This will always launch the Python 3 interpreter.

Setuptools & Pip¶

The two most crucial third-party Python packages are setuptools and pip.

Once installed, you can download, install and uninstall any compliant Python software product with a single command. It also enables you to add this network installation capability to your own Python software with very little work.

Python 2.7.9 and later (on the python2 series), and Python 3.4 and later include pip by default.

To see if pip is installed, open a command prompt and run

To install pip, follow the official pip installation guide — this will automatically install the latest version of setuptools.

Note that on some Linux distributions including Ubuntu and Fedora the pip command is meant for Python 2, while the pip3 command is meant for Python 3.

However, when using virtual environments (described below), you don’t need to care about that.

Pipenv & Virtual Environments¶

The next step is to install Pipenv, so you can install dependencies and manage virtual environments.

A Virtual Environment is a tool to keep the dependencies required by different projects in separate places, by creating virtual Python environments for them. It solves the “Project X depends on version 1.x but, Project Y needs 4.x” dilemma, and keeps your global site-packages directory clean and manageable.

For example, you can work on a project which requires Django 1.10 while also maintaining a project which requires Django 1.8.

This page is a remixed version of another guide, which is available under the same license.

Источник

Оцените статью
Adblock
detector