This week, the Python community released the first version of the Python 3.6 series, which was the first Python release since the introduction of the official Python 3 interpreter in November of 2015.
It includes a number of new features, including the ability to compile Python 3 code directly into Python 3 modules, the ability for Python to be run on Unix-like platforms, the addition of the “Python 3.4” release, and the ability, as of version 3.7, to compile an executable from Python 3 files.
All of these new features are included in this first release, but if you’re looking to install Python 3 right now, you’re going to want to take advantage of the package manager for the 3.x series, as it comes with the latest versions of Python 3 and 3-compatible packages.
For most users, this should be enough to get you up and running with Python 3, but there are still a few issues that will keep you from getting your head around all of the new features in Python 3 4.
In this series of posts, we’ll walk you through all of those issues, as well as some of the features that are coming to Python 3 in the coming months.
Installing a Python package¶ There are two ways to install a Python 3 package.
One way is to install it using the package.install script in the Python shell: $ python -m pip install package.py install If you prefer using pip install instead of pip install, you can do that too: $ pip install –user package.python $ python package.setup() You can also use the pip package manager to install and manage Python packages.
To install Python packages with pip, first create a package.yml file: $ pypi –list-packages python -u root $ pip -m install python-package.yaml You can now use pip install to install any Python package.
Note that pip install works for packages that are not listed in the default PYTHONPATH environment variable.
The pip install script is invoked automatically when you run python -M pypython.py or pip install -r –user .
When using this command, you’ll get a list of installed Python packages and the version number of each.
Instaling a Python module¶ There’s a second way to install packages in Python.
This involves installing a Python 2 or 3 module.
To do this, install a module using the pypy command: $ ./py-install.py import py3rd5 If you’re not familiar with this command in the python shell, here’s a brief description of what it does: Pypy will install a python module into your current working directory, and then it will install all the required Python modules (with the exception of py3d) into your package.pyd file.
You’ll need to specify a directory for the Python modules that you want to install.
If you want py3ds to be installed into the py3 directory, you need to add the following line to your py3.conf file: # py3DSO_HOME=py3rd,pypy:path_to_py3_modules If you’d like py3 to be placed into the same directory as the Python module that you installed, you’d need to put the following into the /usr/lib/python3/dist directory: # Py3DSORR=/usr/local/lib:path/to/py3,path_of/py:modules If this line isn’t present, py3 will not be installed.
For example, to install py3 in the py directory: $ py3 install py This will install py in the /home/python/.python directory.
Instancing a Python class¶ You can use the py2_class and py3_class module modules to build Python classes from Python source files.
This is great if you want a Python-like object-oriented language that doesn’t need to use global variables.
If the code you want is just a subclass of some other class, you don’t need the module.py file to build the class.
Just use the import command, which will import the file from the py source file and create a new module called py2.py : $ python2_module.py MyModule.py This will create a module called MyModule, which in turn will load the MyModule class from the PyPy source file.
This works because PyPy has the PyObject class already defined, and PyPy uses the PyObj object for this.
To add a new class, just use the new_class() function, which is the same function that PyPy calls when it adds a new PyObject object: $ new_name = py.object.__name__(MyModule); $ MyModule = new MyModule(); $ py2 module