I'm trying FastAPI but I can't even run the Hello World example.
I've installed both uvicorn and fastapi with a venv and requirements.txt, also I'm running Python 3.5 (maybe that's the issue?)
The issue should be something with uvicorn because I can't run --help or --version
uvicorn --version
Traceback (most recent call last):
File "/home/...../.venv/bin/uvicorn", line 7, in <module>
from uvicorn.main import main
File "/home/...../.venv/lib/python3.5/site-packages/uvicorn/__init__.py", line 1, in <module>
from uvicorn.config import Config
File "/home/...../.venv/lib/python3.5/site-packages/uvicorn/config.py", line 131
message = f"Uvicorn running on {ip_repr} (Press CTRL+C to quit)"
^
SyntaxError: invalid syntax
I really don't have a clue where to start looking as I cannot seem to find anything on internet.
Surely with Python 3.5, FastAPI won't work.
FastAPI homepage:
FastAPI is a modern, fast (high-performance), web framework for building APIs with Python 3.6+ based on standard Python type hints.
uvicorn (from https://github.com/encode/uvicorn):
Requirements: Python 3.6+ (For Python 3.5 support, install version 0.8.6.)
I guess you should update Python to 3.6 at least. pyenv should help.
Related
Unable to install gcloud sdk using package "google-cloud-sdk-307.0.0-darwin-x86_64.tar.gz" downloaded from gcloud.
Supported Python versions are 3.5 to 3.7, and 2.7.9 or higher
Does it mean Python 3.7.4 is not supported?
enter code here
$ python3 -V
Python 3.7.4
$ which -a python3
/usr/local/bin/python3
/usr/bin/python3
$ ./google-cloud-sdk/install.sh
Welcome to the Google Cloud SDK!
Traceback (most recent call last):
File "/Users/spalani/Documents/DownloadPackages/./google-cloud-sdk/bin/bootstrapping/install.py", line 12, in <module>
import bootstrapping enter code here
File "/Users/spalani/Documents/DownloadPackages/google-cloud-sdk/bin/bootstrapping/bootstrapping.py", line 39, in <module>
from googlecloudsdk.core import config
File "/Users/spalani/Documents/DownloadPackages/google-cloud-sdk/lib/googlecloudsdk/core/config.py", line 33, in <module>
from oauth2client import client
File "/Users/spalani/Documents/DownloadPackages/google-cloud-sdk/lib/third_party/oauth2client/client.py", line 39, in <module>
from oauth2client import transport
File "/Users/spalani/Documents/DownloadPackages/google-cloud-sdk/lib/third_party/oauth2client/transport.py", line 17, in <module>
import httplib2
File "/Users/spalani/Documents/DownloadPackages/google-cloud-sdk/lib/third_party/httplib2/__init__.py", line 20, in <module>
from httplib2.python3.httplib2 import *
File "/Users/spalani/Documents/DownloadPackages/google-cloud-sdk/lib/third_party/httplib2/python3/httplib2/__init__.py", line 40, in <module>
import ssl
File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 98, in <module>
import _ssl # if we can't import it, let the error propagate
ImportError: dlopen(/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload/_ssl.cpython-37m-darwin.so, 2): Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib
Referenced from: /usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload/_ssl.cpython-37m-darwin.so
Reason: image not found
Regarding your question “Does it mean Python 3.7.4 is not supported?”
According to this document:
Cloud SDK runs on Linux, macOS, and Windows. Cloud SDK requires Python. Supported versions are 3.5 to 3.7, and 2.7.9 or higher.
So, it seems that it is supported for the Cloud SDK installation.
On the other hand, I have found the following guide to configure the Python interpreter, it could help you to set it properly.
Also, It appears that the recommended option to install SDK on MacOS is through the interactive installer.
For Windows and macOS interactive installations, and all other use cases, run the interactive installer to install the latest release of Cloud SDK.
The steps to install it using the Google Cloud SDK installer are:
Enter the following at a command prompt:
curl https://sdk.cloud.google.com | bash
Restart your shell:
exec -l $SHELL
Run gcloud init to initialize the gcloud environment:
gcloud init
I hope you find this information useful.
When I try to run my server using:
./manage.py runserver 0.0.0.0:8000
I get the following error:
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
from django.core.management import execute_from_command_line
ImportError: No module named django.core.management
After browsing for a solution, I learned that Django was not installed so I tried installing it on a VM.
I tried the following:
pip install django
yum install django
yum install python-django
I also tried running these commands with sudo -s and sudo -E.
I am getting the following when I use pip cmd:
Downloading/unpacking django
Cannot fetch index base URL https://pypi.python.org/simple/
Could not find any downloads that satisfy the requirement django
No distributions at all found for django
Storing complete log in /root/.pip/pip.log
Using Yum I get:
No package python-django available.
Error: Nothing to do
Install a new version of Python. Pip has to be installed for the new
version. CentOS 6.6 has default Python 2.6 and the default pip
doesn't work properly.
Install Django with new pip.
Do not install the new version of Python globally as CentOS relies on
Python 2.6 for yum.
I installed pygame on my Arch Linux machine with the following command:
$ sudo pacman -S python2-pygame
I am using pyenv and the version of Python in my virtual environment for this project is 2.7.11
When I run my program
$ python smartcab/agent.py
here is what I get:
Traceback (most recent call last):
File "smartcab/agent.py", line 2, in <module>
from environment import Agent, Environment
File "/home/alex/machine-learning/projects/smartcab/smartcab/environment.py", line 5, in <module>
from simulator import Simulator
File "/home/alex/machine-learning/projects/smartcab/smartcab/simulator.py", line 4, in <module>
import pygame
ImportError: No module named pygame
How can I solve this please?
On my own Arch Linux machine...
I have created a 2.7.11 virtualenv using pyenv and installed python2-pygame with pacman. With my virtualenv activated, I couldn't import pygame from python. So I was able to reproduce your issue.
After that, I tried downloading and compiling pygame's source with python setup.py install without success. It is complaining about a missing linux/videodev.h which seems to be (from what I found on the web) deprecated and replaced by linux/videodev2.h (which is there).
I won't go further, I hope this will help someone finding the solution.
I'm following this for django manage.py module
http://docs.ansible.com/django_manage_module.html
for e.g. one of my tasks looks like -
- name: Django migrate
django_manage: command=migrate
app_path={{app_path}}
settings={{django_settings}}
tags:
- django
this works perfectly fine with python2(default in ubuntu) but when I try with python3-django project it throws error
failed: [123.456.200.000] => (item=school) => {"cmd": "python manage.py makemigrations --noinput school --settings=myproj.settings.production", "failed": true, "item": "school", "path": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games", "state": "absent", "syspath": ["/home/ubuntu/.ansible/tmp/ansible-tmp-1432039779.41-30449122707918", "/usr/lib/python2.7", "/usr/lib/python2.7/plat-x86_64-linux-gnu", "/usr/lib/python2.7/lib-tk", "/usr/lib/python2.7/lib-old", "/usr/lib/python2.7/lib-dynload", "/usr/local/lib/python2.7/dist-packages", "/usr/lib/python2.7/dist-packages"]}
msg:
:stderr: Traceback (most recent call last):
File "manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ImportError: No module named django.core.management
from this error it seems Ansible bydefault uses Python2. can we change this to python3 or anyother workaround?
PS: pip freeze ensure that django 1.8 has installed (for python3 using pip3)
Suggestions:
when I run ubuntu#ubuntu:/srv/myproj$ python3 manage.py migrate it works fine. so I'm thinking of passing command directly
something like
- name: Django migrate
command: python3 manage.py migrate
tags:
- django
but how do I pass the project path or manage.py file's path, there is only an option to pass settings, something like --settings=myproject.settings.main.
can we do by passing direct command?
From Ansible website http://docs.ansible.com/intro_installation.html
Python 3 is a slightly different language than Python 2 and most Python programs (including Ansible) are not switching over yet. However, some Linux distributions (Gentoo, Arch) may not have a Python 2.X interpreter installed by default. On those systems, you should install one, and set the ‘ansible_python_interpreter’ variable in inventory (see Inventory) to point at your 2.X Python. Distributions like Red Hat Enterprise Linux, CentOS, Fedora, and Ubuntu all have a 2.X interpreter installed by default and this does not apply to those distributions. This is also true of nearly all Unix systems. If you need to bootstrap these remote systems by installing Python 2.X, using the ‘raw’ module will be able to do it remotely.
If you edit the shebang in the Django manage.py file to be #!/usr/bin/env python3 then you can ensure that python 3 will always be used to run your Django app.
Tried successfully with Ansible 2.3.0 and Django 1.10.5. YMMV
Ansible is using python to run the django command: https://github.com/ansible/ansible-modules-core/blob/devel/web_infrastructure/django_manage.py#L237
Your only solution is thus to override the executable that will be run, for instance by changing your PATH:
- file: src=/usr/bin/python3 dest=/home/user/.local/bin/python state=link
- name: Django migrate
django_manage: command=migrate
app_path={{app_path}}
settings={{django_settings}}
environment:
- PATH: "/home/user/.local/bin/:/bin:/usr/bin:/usr/local/bin"
So, I have python 2.7.3 installed and I used the Django website https://docs.djangoproject.com/en/dev/topics/install/ to install Django on my Mac OS x Mountain Lion. I used pip and virtual env, I currently am able to use Django from my current terminal but, when I open a new terminal and try say:
$ cd Django
$ cd djangowork
$ cd firstproj
$ python manage.py runserver
Traceback (most recent call last):
File "manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ImportError: No module named django.core.management
This is the error I get.
I have looked online for a solution to my problem. It seems to be a common problem, dealing with the PATH. But, I cannot figure out how to fix it. Any help would be much appreciated thanks!
This is an example of what my working terminal looks like: (but if I exit out I lose everything)
(my_new_env)$ cd Django
(my_new_env)$ cd djangowork
(my_new_env)$ cd firstproj
(my_new_env)$ ls
firstproj manage.py testdb
(my_new_env)$ python manage.py runserver
Validating models...
0 errors found
October 31, 2012 - 18:51:22
Django version 1.6.dev20121029143154, using settings 'firstproj.settings'
Development server is running at http://.../
Quit the server with CONTROL-C.
Notice how in the second case you have (my_new_env) before the prompt, but not in the first? That's because only in the second case have you run virtual env properly. Make sure you run source my_new_env/bin/activate before you run any python commands at the prompt. You should always have (my_new_env) before the prompt in order to make sure your environment is set up properly. You have to do this in every terminal window that you open.