How to Install Python 2 on FreeBSD 14

Compile and Install Python 2

Follow the steps below to compile and install Python 2 from source code.

  1. Verify the default Python version.
    CONSOLE
    $ python --version
    

    Output.

    Python 3.11.11

    The above output confirms that Python 3 is the system’s default Python binary.

  2. Python 2 is no longer in FreeBSD’s package repositories. Download the Python 2.7 source from the Python releases page.
    CONSOLE
    $ wget https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz
    
  3. Extract all files from the downloaded tarball.
    CONSOLE
    $ tar -xvzf Python-2.7.18.tgz
    
  4. Navigate to the extracted directory.
    CONSOLE
    $ cd Python-2.7.18
    
  5. Run the configuration script with shared library support.
    CONSOLE
    $ ./configure --with-system-ffi --with-computed-gotos --enable-shared
    
  6. Compile using all CPU cores for faster processing.
    CONSOLE
    $ make -j$(sysctl -n hw.ncpu)
    
  7. Install Python 2 without overwriting the default Python binary.
    CONSOLE
    $ sudo make altinstall
    

Test the Python 2 Installation

Follow the steps below to test the Python 2 installation on your FreeBSD server.

  1. Verify the installation.
    CONSOLE
    $ python2.7 --version
    

    Output:

    Python 2.7.18
  2. Check the default Python binary version.
    CONSOLE
    $ python --version
    

    Output:

    Python 3.11.11

    You can see that both versions are now available on your instance.

  3. Create a symbolic link to allow the python2 command to run the python2.7 binary.
    CONSOLE
    $ sudo ln -s /usr/local/bin/python2.7 /usr/local/bin/python2
    

Compile and Install PIP for Python 2

Pip is the standard Python package manager for managing Python packages and dependencies in your projects. Python 2 doesn’t include Pip by default, so you’ll install it manually.

  1. Download the Pip installation script for Python 2.
    CONSOLE
    $ wget https://bootstrap.pypa.io/pip/2.7/get-pip.py
    
  2. Install Pip for Python 2.7.
    CONSOLE
    $ sudo python2.7 get-pip.py
    
  3. Verify the Pip installation.
    CONSOLE
    $ pip2.7 --version
    

    Output.

    pip 20.3.4 from /usr/local/lib/python2.7/site-packages/pip (python 2.7)

Test and Use Python 2

It’s important to verify that everything works as expected after completing the installation. Follow the steps below to test your Python 2 installation.

  1. Launch the Python 2 interpreter.
    CONSOLE
    $ python2
    
  2. Run the following command to display a Hello World, Greetings from Vultr! message in your terminal.
    PYTHON
    >>> print('Hello World, Greetings from Vultr!')
    

    Output.

    Hello World, Greetings from Vultr!
  3. Exit from the Python shell.
    PYTHON
    >>> quit()
    
  4. To test Pip, install the Flask Python module using Pip.
    CONSOLE
    $ pip2.7 install flask
    

    Output:

    DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python version since Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
    Name: Flask
    Version: 1.1.4
    Summary: A simple framework for building complex web applications.
    Home-page: https://palletsprojects.com/p/flask/
    Author: Armin Ronacher
    Author-email: armin.ronacher@active-4.com
    License: BSD-3-Clause
    Location: /home/jsah/.local/lib/python2.7/site-packages
    Requires: click, Jinja2, Werkzeug, itsdangerous
    Required-by:

Conclusion

You now have a fully functional Python 2.7 binary on your FreeBSD 14 instance that coexists with the system’s default Python 3 binary. This setup allows you to run legacy applications while maintaining modern Python support. For additional guidance on working with legacy codebases, refer to the Python 2.7 documentation.

Compile and Install Python 2 Follow the steps below to compile and install Python 2 from source code. Verify the default Python version. CONSOLE $ python –version Output. Python 3.11.11 The above output confirms that Python 3 is the system’s default Python binary. Python 2 is no longer in FreeBSD’s…

Compile and Install Python 2 Follow the steps below to compile and install Python 2 from source code. Verify the default Python version. CONSOLE $ python –version Output. Python 3.11.11 The above output confirms that Python 3 is the system’s default Python binary. Python 2 is no longer in FreeBSD’s…

Leave a Reply

Your email address will not be published. Required fields are marked *