Library python asyncio

Asked

Viewed 119 times

3

Hello, I am trying to install the asyncio library for Python 2.7.13 but I am not getting success, follow the error:

rafamt@rafamttz:~$ Pip install asyncio`

Collecting asyncio Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after Connection Broken by 'Protocolerror('Connection aborted. ', error(107, 'Transport endpoint is not Connected'))': /simple/asyncio/ Installing collected Packages: asy`

Exception: Traceback (Most recent call last): File "/home/rafamttz/. local/lib/python2.7/site-Packages/Pip/basecommand.py", line 215, in main status = self.run(options, args) File "/home/rafamttz/. local/lib/python2.7/site-Packages/Pip/Commands/install.py", line 342, in run prefix=options.prefix_path, File "/home/rafamttz/. local/lib/python2.7/site-Packages/Pip/req/req_set.py", line 784, in install **kwargs File "/home/rafamttz/. local/lib/python2.7/site-Packages/Pip/req/req_install.py", line 851, in install self.move_wheel_files(self.source_dir, root=root, prefix=prefix) File "/home/rafamttz/. local/lib/python2.7/site-Packages/Pip/req/req_install.py", line 1064, in move_wheel_files Isolated=self.Isolated,File "/home/rafamttz/. local/lib/python2.7/site-Packages/Pip/wheel.py", line 345, in move_wheel_files Clobber(source, lib_dir, True) File "/home/rafamttz/. local/lib/python2.7/site-Packages/Pip/wheel.py", line 316, in Clobber ensure_dir(destdir) File "/home/rafamttz/. local/lib/python2.7/site-Packages/Pip/utils/init.py" line 83, in ensure_dir os.makedirs(path) File "/usr/lib/python2.7/os.py", line 157, in makedirs mkdir(name, mode) Oserror: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-Packages/asyncio'

How do I install this library? What is needed?

  • 1

    It was only added in version 3.4. Why you need to use version 2.7?

  • Well, I’m using python 2.7 on my Crossbar.io server (WAMP/Web Socket router), but I’ve never tried using a different python version than the server. I have to connect my computer to the server

  • Couldn’t use the twisted library?

1 answer

3

Recoding for development is using the latest Python - 3.6 - installing Python 3.6 on your server is a trivial problem compared to trying to create using asynchronous code for Python 2.

But basically: when the idea of consolidating async in Python through the Asyncio API came up, Python 2 was already obsolete a few years ago. And it’s not getting any less obsolete now.

In the past a library called Trollius was maintained specifically to offer the same functionality as "asyncio" (which then had the codename "Tulip" - "Trollius" is the name of another flower).

So even if you get around the problem of this issue and install some version of Asyncio or library with some compatibility that works in Python 2, this will be of little use, since none of the Async libraries for effective input and output (async versions to serve HTTP, or connect to the database) will work in Python 2. - Not to mention any example of code.

Having said all that, more likely your server has Python 3 -or already installed, or available as a package - is just a matter of writing "python3" instead of Python.

Anyway, your project should make use of a "vitualenv": this is an isolated environment in user folders (not root), which has own versions of each library to be used - (this would render the above error, caused precisely by the installation program wanting to save the asyncio files to a system folder - in /usr/local) .

So - general recommendations: read some virtualenv documentation. Practice on your local machine - you don’t have to do it right on the server. If your local machine is Windows, put a Linux virtual machine: it’s less complicated to develop. That done, and having started the project, if the version of Python 3 on your server is less than 3.6, Compile a Python 3.6 bvyou even there - Python is an easy-to-compile Relativametne project without interfering with the system’s Python.

Create your Python project with file verses, and in a way that works inside a virtualenv. Ready - at this point you are ready to develop a project that can go to production,and use updated biblitoecas.

updating The recommendation for async code, or any Python project is to always use the latest stable version. Right now it’s 3.7 and we’re just a few weeks away from the official launch of the 3.8. It is common for people to restrict projects to older versions of the language because of the version of Python3 installed on the servers - even on servers with LTS-like distributions like Centos or Ubuntu, Python can be 3.5 (from 4 years ago and without much of the recent features).

The way to go in such cases is either to install the latest Python3 from an official repository, or to compile your own Python 3 in the destination. This is easier to do than it sounds - my recommendation is to use the project "pyenv" to take care of it. From the moment you have the newest Python, just use it to create the virtual environments (virtualenv or equivalent) of the projects, and it will work without any difference to the native Python3 of the distribution, and with all the dependencies created as a user file, without needing anything from the system, or with root.

The only thing is that the Pyenv documentation does not seem to speak of the system requirements for compiling Python3. Both Ubuntu and other Debian Based, as well as Centos and other Redhat based have the "builddep" directive of the package manager - the command apt builddep python3 (plus apt install libcffi-dev or equivalent, in case Python system is less than 3.6), in general it is enough to install everything the system needs so that Pyenv can compile Python 3 in any version desired, without giving any error.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.