Archive

Archive for the ‘python’ Category

OSError: [Errno 8] Exec format error

June 5, 2019 Leave a comment

Problem:
$ python3 run.py
* Serving Flask app "petsrus.petsrus" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
* Restarting with stat
Traceback (most recent call last):
File "run.py", line 4, in
app.run(host="0.0.0.0", port=5000)
File "/home/vagrant/env/lib/python3.4/site-packages/flask/app.py", line 944, in run
run_simple(host, port, self, **options)
File "/home/vagrant/env/lib/python3.4/site-packages/werkzeug/serving.py", line 1007, in run_simple
run_with_reloader(inner, extra_files, reloader_interval, reloader_type)
File "/home/vagrant/env/lib/python3.4/site-packages/werkzeug/_reloader.py", line 332, in run_with_reloader
sys.exit(reloader.restart_with_reloader())
File "/home/vagrant/env/lib/python3.4/site-packages/werkzeug/_reloader.py", line 176, in restart_with_reloader
exit_code = subprocess.call(args, env=new_environ, close_fds=False)
File "/usr/lib/python3.4/subprocess.py", line 537, in call
with Popen(*popenargs, **kwargs) as p:
File "/usr/lib/python3.4/subprocess.py", line 859, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.4/subprocess.py", line 1457, in _execute_child
raise child_exception_type(errno_num, err_msg)
OSError: [Errno 8] Exec format error


Solution:

Added #!/usr/bin/env python to the file

#!/usr/bin/env python
from myapp import app

if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)


Source:

https://stackoverflow.com/questions/27606653/oserror-errno-8-exec-format-error

Advertisements
Categories: python

Vim as a Python IDE

February 1, 2019 Leave a comment

VIM as a Python IDE

This project aims to use Vim as a powerful and complete Python IDE. In order to do that, we curated a list of awesome plugins available in the community and provided an automatic installation procedure for this set.

https://rapphil.github.io/vim-python-ide/

Source:
https://www.pythonweekly.com/

Categories: Interesting, python, vim Tags:

Designing Well-Structured REST APIs with Flask-RestPlus: Part 1

December 11, 2018 Leave a comment

This is the first part of a two-part series. In this post, I will introduce Flask-RestPlus and demonstrate how to start organising APIs around its simple REST-based conventions. Next time, I will address the topic of request/response marshalling (serialisation) and validation.

https://preslav.me/2018/12/02/designing-well-structured-rest-apis-with-flask-restplus-part-1/

Categories: python Tags:

pip – ImportError: cannot import name main

December 7, 2018 Leave a comment

Problem:
Getting above error when running pip

ubuntu@ubuntu-xenial:~$ pip install --upgrade pip
Collecting pip
  Downloading https://files.pythonhosted.org/packages/c2/d7/90f34cb0d83a6c5631cf71dfe64cc1054598c843a92b400e55675cc2ac37/pip-18.1-py2.py3-none-any.whl (1.3MB)
    100% |████████████████████████████████| 1.3MB 646kB/s 
Installing collected packages: pip
Successfully installed pip-8.1.1
You are using pip version 8.1.1, however version 18.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.


ubuntu@ubuntu-xenial:~$ pip install --upgrade pip
Traceback (most recent call last):
  File "/usr/bin/pip", line 9, in <module>
    from pip import main
ImportError: cannot import name main

Solution:

ubuntu@ubuntu-xenial:~$ python -m pip install -U pip
Requirement already up-to-date: pip in ./.local/lib/python2.7/site-packages (18.1)

Source:
https://stackoverflow.com/questions/28210269/importerror-cannot-import-name-main-when-running-pip-version-command-in-windo

Categories: python

Brett Slatkin – How to Be More Effective with Functions – PyCon 2015

November 8, 2018 Leave a comment

Functions improve readability, encourage reuse, and facilitate refactoring. Python has many unique features that make functions significantly more powerful. This talk will show you the best ways to use functions in Python: when *args is helpful and when it’ll crash your programs; how to use generators for arguments and return values; the value of keyword vs. keyword-only arguments; and more!

Categories: Interesting, python

Kenneth Reitz – Pipenv: The Future of Python Dependency Management – PyCon 2018

October 22, 2018 Leave a comment

Speaker: Kenneth Reitz

This talk is about the history of Python packaging, the tools that have been historically available for application deployment, the problems/constraints presented by them, and presents a holistic solution to many of these problems: Pipenv.

A live demo of the tool will be presented, as well as a Q&A session.

Slides can be found at: https://speakerdeck.com/pycon2018 and https://github.com/PyCon/2018-slides

Categories: Interesting, python Tags:

How to Add User Authentication to Flask Apps with Okta

October 18, 2018 Leave a comment

User authentication is a basic feature in web applications so people can create and access their own accounts. Unfortunately, authentication is not always easy to set up and there are many ways to incorrectly implement login and logout features.

This tutorial walks through how to use the secure identity authentication service called Okta, which is free for up to 1,000 active user accounts, to easily handle user data in Flask applications.

https://www.fullstackpython.com/blog/add-user-authentication-flask-apps-okta.html

Categories: Interesting, python