Setting up local environment with Google Cloud SDK - python

I'm new to Python. Trying to work get this Google Cloud Python tutorial. I'm stuck at the part where it say "Installing dependencies" where do I run this virtualenv -p python3 env and other code?
Tried running them in the Google Cloud SDK Shell inside that particular folder that just says it's "not a recognized command"
Just having difficulty setting this local environment, can someone help?

At some point it was a command in the tutorial :
git clone https://github.com/GoogleCloudPlatform/getting-started-python.git
cd to the directory that contains the requirements.txt file:
and then run (assuming you have installed virtualevn in your machine):
virtualenv -p python3 env
source env/bin/activate
pip install -r requirements.txt

Tutorial you are referring to is one part of deploying a complex Python app. With an assumption that you already completed the setup instructions.
This page is part of a multipage tutorial. To start from the beginning
and read the setup instructions, go to Python Bookshelf app.
You will need to go through the setup instructions before starting. Again it assumes that, you have Python development environment set up. If not please follow Setting Up a Python Development Environment

Related

Azure self hosted windows agent, What is the {tool files} in Use Python Version configuration?

UPDATE:
Now that I tried the solution from the answers to try
python -m ensurepip
python -m pip install --upgrade pip
pip install tox poetry
I realize that the self-hosted windows agent apparently did not even have the python. I followed this instruction from azure: use python version
where they say something like the direction structure.
$AGENT_TOOLSDIRECTORY/
Python/
3.6.4/
x64/
{tool files}
x64.complete
what is confusing is the definition of {tool files}
Initially, I downloaded the python executable from the website This gave me an .exe file. So I created a folder structure in c:/agent/_work/_tool/ as below
$AGENT_TOOLSDIRECTORY/
Python/
3.9.9/
x64/
python_3.9.9-amd64.exe
x64.complete
Since this is definitely not the right way to do it. I am not sure what is the definition of {tool files}. I am currently stuck on how to correctly install python on the self-hosted windows agent.
Then I tried to use a venv to create folder architecture as advised in
Link. Since the demo is for Linux, the venv installation turned out to be different. There was no bin folder created. And instead a pyvenv.cfg file was created. This venv configuration referred to path where the python was originally installed. The folder structure was as follows when I did this.
$AGENT_TOOLSDIRECTORY/
Python/
3.6.4/
x64/
Include/
Libs/
Scripts/
pyvenv.cfg
x64.complete
This made the powershell task that was discussed below to fail as follows. From the cfg file the powershell tried to look for the python in users' folder istead of the _tool` folder.
I am lost here, any help is appreciated.
Thanks a lot.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++
EARLIER ISSUE:
I am trying to create a Pipeline for my python project using self-hosted Windows agent.
Here is the link to my repository where you can find the azure yml files. https://GringottsFinance#dev.azure.com/GringottsFinance/NLNETSalaryCalculator.Py/_git/NLNETSalaryCalculator.Py
For the tox related steps, I created this template
parameters:
PythonVersion: ''
ToxEnvironment: ''
steps:
- checkout : self
fetchDepth: 1
- task: UsePythonVersion#0
displayName: Use Python Version ${{ parameters.PythonVersion }}
inputs:
versionSpec: ${{ parameters.PythonVersion }}
condition: succeeded()
- powershell: pip install tox poetry
displayName: Install Tox and Poetry
condition: succeeded()
- powershell: tox -r -e ${{ parameters.ToxEnvironment }}
displayName: Run the give Tox Environment
condition: succeeded()
My problem is that even though the python version 3.9.9 is successfully installed in the agent, the PowerShell doesn't seem to find the pip.
I have tried adding the path to environment variables.
I have also restarted the agent several times after adding the variables.
None of the solutions seem to work. Any help is appreciated.
Azure self hosted windows agent's powershell can not find pip
I could reproduce this issue on my side.
You could resolve that issue with the following commands:
python -m ensurepip
python -m pip install --upgrade pip
pip install tox poetry
The test result:
Okay, I figured out the solution on how to successfully install a windows self-hosted agent and configure python in it.
Here are the steps.
Create a folder structure as follow inside the folder where the windows-agent-pool was configured.
$AGENT_TOOLSDIRECTORY/
Python/
3.9.9/
x64/
{tool files}
x64.complete
Now comes the tricky part
What do the {tool files} even mean. Here is what worked for me.
I downloaded the windows installer for python from python-3.9.9-amd64.exe - Click to download
Run the executable.
Choose custom installation (Really important)
Select all the checkboxes that appear.
Select the above folder location as the directory where you wanted to install python. i.e. the directory we just created. So the installation location of python should be $AGENT_TOOLSDIRECTORY/Python/3.9.9/x64/
P.S. If you had followed the Microsoft instruction while installing the agent. your $AGENT_TOOLSDIRECTORY is just C:/agent/_work/_tool/. So the installation path for python should just be C:/agent/_work/_tool/Python/3.9.9/x64/
Ufff... that only took me three sleepless nights to figure out. Hope some of you can find a better use of the answer.
Thanks.

How to install and use python libraries in mac using PIP with terminal

Firstly i'm new to python environment.
I installed PIP in mac using terminal and the python version is 2.7.16. I want to install and use Simple Image annatator(https://github.com/sgp715/simple_image_annotator).
I install flask(pip install flask) and i did cd into the cloned folder if simple image annotator. For reference please see the github repo for installation steps.
Than after i don't know what to do to use this library if i run this command(python app.py /images/directory) it gives No files.
How can i install and use the simple image annotator in mac can somebody please tell me the setup process steps.
working with python libraries is entirely new to me. Thanks in advance.
BELOW IS EDITED QUESTION FOR MORE EXPLANATION:
I installed flask and moved to the cloned folder please see the terminal commands as shown in screenshot.
Next remaining installation steps are:
start the app
$ python app.py /images/directory
you can also specify the file you would like the annotations output to (out.csv is the default)
$ python app.py /images/directory --out test.csv
open http://127.0.0.1:5000/tagger in your browser
only tested on Chrome
I don't know how to execute remaining steps. images are available in downloads/images folder in my mac.
How to execute these commands?
Screenshots to explain more:
The problem can be from your python version.
Try with python3 (if installed)
python3 app.py /images/directory

Python can't find my Flask script under virtualenv

I'm trying to build a simple API server using Flask that will validate and store international phone numbers using this phonenumbers.py. I previously installed Flask and several Flask extensions in a virtualenv, and started building my app. So far so good. But after downloading and installing phone numbers.py using its own installer, I found that python running inside virtualenv could no longer find my app script! Looking at the directory, it's sitting right there, but python does not recognize it any more. The only other wrinkle I can think of is that after doing the install, I used an external text editor (outside the venv) to edit my app script and re-save it.
What have I done wrong?
I compared my environment variables inside and outside virtualenv. They are the same except for the following 3 additions:
VIRTUAL_ENV=/Users/tokrum/callcenter/venv
PATH=/Users/tokrum/callcenter/venv/bin # (was added to the beginning of my $PATH, but the rest of pre-existing PATH is as beforeā€¦.)
PS1=(venv)\h:\W \u\$
My app is called callcenter-v0-1.py. It lives in a directory called /callcenter/, along with the phone numbers-7.0.1 and venv folders at the same level of my directory structure.
Thanks for any light you can shed on this.
Install Flask_script in your virtual env using
$pip install Flask-Script
Make sure that you activated the virtualenv before you installed Flask and your other dependencies -
$ virtualenv env
$ source env/bin/activate
$ pip install flask
Then when you're done working, make sure to deactivate the environment -
$ deactivate
Finally, when you want to start working again, navigate to your project directory and reactivate the environment -
$ source env/bin/activate
At this point, I would just remove the virtualenv and start over.
Hope that helps!

ckan.plugins.core.PluginNotFoundException: pages

I'm using CKAN as my open data portal. It's written in Python using Pylons framework. I just want to add a new page similar to about page to display the terms and conditions to the users. About page comes built in.
So I installed ckanext-pages using pip command. What I did was below
1. # Activate your CKAN virtual environment
. /usr/lib/ckan/default/bin/activate
2. # Install the pages extension.
pip install -e 'git+https://github.com/ckan/ckanext-pages.git#egg=ckanext-pages'
But now I end up with below error which is given when a requested plugin cannot be found.
ckan.plugins.core.PluginNotFoundException: pages
Plugin resides on below path
/usr/lib/ckan/default/src
Please let me know how to fix this?
With your virtualenv activated, run python setup.py develop in the ckanext-pages folder. This will register the plugin so CKAN can find it.
had similar issue. Double-check which paster you are using by command:
which paster
it must show you paster from your current virtualenv, which was /usr/lib/ckan/default in your case
if you are trying #amercader answer, and getting error13 permission denied, with your venv activated:
which python, this will get the path to python in your venv, grap that
run sudo the_path_you_just_grapped setup.py develop
then run the database initialization as in here

Importing and debugging a Python Django project made in a different environment

I am working on a Django project that was created by another developer on a different machine. I see that in the root of the application, there is a .virtualenv directory. Is it possible to simply setup this project locally on my Windows machine using the project settings and Python version (the app uses 2.7), so that I can run it like a local Django application so debugging is feasible?
I have access to the development web server and have copied the full source of the app down to my Win7 machine but cannot seem to get things setup correctly to run the app locally so I can debug.
I currently have Python 2.7, 2.7.5 and 3.3.2 installed on my local dev machine. I would call myself pretty new to Django and Virtualenv.
If anyone has any guidance on how I can get my environment straitened out so I can run the app with debugging, I would be very thankful.
Thank you in advance.
Using a virtualenv environment created on a different machine is not recommended. There are things hard-wired for the particular system it was created on, and some apps may have components compiled for that particular system.
You should create a new virtualenv environment on your machine, install dependencies and move the Django project there.
Note on installing dependencies - there might be a file named requirements.txt somewhere. If it's there and it's kept up to date you can install all the dependencies by running a single command while in your virtualenv:
pip -r requirements.txt install
If you can't find it ask the other developer to create it. He just need to do this inside his own environment:
pip freeze > requirements.txt
I once faced the same problem and it took me so much time to configure another environment that I eventually had to create a VM with the same version of OS and libraries. I then made a raw copy of the project and it worked fine.

Categories