I want to make use of Python 3.4 x86 as my build target. Microsoft hosted agents don't have that as an option - 3.5 is the lowest version 3x branch.
Can I just install python during run process - still use Microsoft hosted agent but with python version I like?
The UsePythonVersion doesn't install it.
It seems that you are using Hosted agent vs2017-win2016 and we can see that the Python version installed by the agent does not contain Python 3.4
Check the task prerequisites:
A Microsoft-hosted agent with side-by-side versions of Python installed, or a self-hosted agent with Agent.ToolsDirectory configured (see FAQ).
This task will fail if no Python versions are found in Agent.ToolsDirectory. Available Python versions on Microsoft-hosted agents can be found here.
As a workaround, we should install the Python 3.4 via command line and then use the task Use Python version to specify the Python version. Check this doc for more details.
Update1
It seems that we cannot install 3.4 in the hosted agent.
TEST1 install python via power shell script:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest -Uri "{URL}" -OutFile "$(Build.SourcesDirectory)/{python install file .exe}"
$(Build.SourcesDirectory)/{python install file .exe} /quiet InstallAllUsers=0 PrependPath=1 Include_test=0
But cannot found python 3.4 exe file in the download website.
TEST2 install the python via extension.
Extension: Python build tools
Task: Install Python on Windows
According to the json file, we can see that 3.5.2 is the lowest version.
Hmm. Exe isn’t there but msi’s are. They take same options as EXE I believe
If you are using a customized agent You need to add an environment for AGENT_TOOLSDIRECTORY and a python folder structure (https://go.microsoft.com/fwlink/?linkid=871498).
In my case, I did in docker file used to generate the agent.
ENV AGENT_TOOLSDIRECTORY="/AGENT_DEVOPS"
RUN mkdir /AGENT_DEVOPS
RUN mkdir /AGENT_DEVOPS/Python
# python 3.8
RUN mkdir /AGENT_DEVOPS/Python/3.8.0
RUN apt-get install python3.8-venv
RUN python3.8 -m venv /AGENT_DEVOPS/Python/3.8.0/x64
RUN touch /AGENT_DEVOPS/Python/3.8.0/x64.complete
# python 3.7
RUN mkdir /AGENT_DEVOPS/Python/3.7.5
RUN apt-get install python3.7-venv
RUN python3.7 -m venv /AGENT_DEVOPS/Python/3.7.5/x64
RUN touch /AGENT_DEVOPS/Python/3.7.5/x64.complete
Related
I created an Azure Redhat Linux VM that came pre-installed with python 2.7.5. I need to update it to the latest version so I can then install databricks CLI on it to access DBFS. Need help on how to do this, please.
Tried:
$ sudo yum update python
Result:
Loaded plugins: langpacks, product-id, search-disabled-repos
No packages marked for update
I need at least 2.7.9 version of python to be able to install databricks CLI.
I don't have an on-prem Linux server. Only have Windows and don't have admin access to install python on PowerShell.
Generally, the default Python version of a Linux distribution is depended on the Linux distribution version. So if you created the latest version of RedHat Linux on Azure VM, you can upgrade the default Python 2 version via the steps below.
Check whether exists an upgrade version of Python you want via yum info python or yum list python.
If there is an upgrade version, you can upgrade it via yum -y upgrade python or yum -y update python.
For older Linux distribution, there is an upper limit version of Python, such as 2.7.5 for Python 2 on your current RedHat Linux VM I guess. So you could not simply upgrade it via the system package manager yum to install an upper version from default package repository. Then, we need to download the source code of a specified version of Python to compile and install on the current environment.
There is a blog How to Install or Upgrade Python in Linux Systems introduces how to do.
Here is my steps to install Python 2.7.9.
Make sure there is compiler tool kits gcc & g++ installed in your current environment. To check via gcc -v and g++ -v. To install via yum -y install gcc gcc-c++ and other dependencies like zlib, zlib-dev, openssl, openssl-dev, ncurses-libs, readline-devel, sqlite-devel, bzip2-devel, gdbm-devel, libdbi-devel, and so on.
Download the source code package from the offical Python FTP via $ wget https://www.python.org/ftp/python/2.7.9/Python-2.7.9.tgz.
Decompress it via tar -zxvf Python-2.7.9.tgz.
cd Python-2.7.9.
If you just want to use Python 2.7.9 temporarily, the next steps are as below.
./configure && make
To configure the PATH environment variable via export PATH=$HOME/<the parent path>/Python-2.7.9/:$PATH
Then, you can use Python 2.7.9 in the current Shell session.
If you want to install Python 2.7.9 into /usr/local and not break the current default Python version to avoid the possible system crash issue, the next steps as as below.
./configure --prefix=/usr/local
make && sudo make altinstall
Then, you can use Python 2.7.9 via python2.7. You can check all Python version via python -V, python2 -V and python2.7 -V.
Hope it helps.
I am having trouble installing the aws CLI for windows.
I am following these instructions here
It requires that I have Python 3.6.2 but I have Python 2.7.6 when I run python --version
After I run
pip install --user --upgrade awscli
and then try to run
aws --version
nothing happens.
I tried setting my path in Environment Variables but it still won't work.
After this, I tried to upgrade my python version by installing python 3.6 on their website, but my python version won't update when I run python --version.
Could this be that start of why I cant install the CLI?
Use this link to download and install AWSCLI Download the AWS CLI MSI installer for Windows
then go to C:\Program Files\Amazon\AWSCLI or where-so-ever you have installed this and set the path in Environment variables.
Cheers!
Have you gone through the steps on the amazon website? Python 2 and 3 are quite different from what I understand.
https://docs.aws.amazon.com/cli/latest/userguide/installing.html
The AWS script you are running is really just a python program. I recommend verifying install paths, and possibly use their bundled installer found on the page above, about half way down.
At first make sure you have installed python3. Check it with command:
Try to verify python version with command(on centos or redhat):
$ rpm -qa|grep python3
And then make sure python3 has been added to $PATH
$python3 --version
And I think you need to install pip3 for python3.X.
$yum search python3|grep pip
And then install the package you need with command
$ pip3 install --user --upgrade awscli
You can develop Python software for AWS in both Python 2.x and 3.x. The CLI is written in Python 2.x.
You can have both Python 2 and Python 3 installed on your system. You can either specify the python.exe manually using its full path (not recommended but I do this all the time) or by updating your environment PATH variable to point to the correct Python installation. I use a batch file so that I can switch back and forth between Python 2 and Python 3.
When you run "pip install --user --upgrade awscli" the version of Python that is running determines the awscli package that is downloaded and installed.
For Microsoft Windows, AWS provides an MSI installer package that contains everything that you need including the correct version of Python 2.7. I recommend that you start with the AWS Windows MSI and then learn how Python works (environment) on Windows.
Keep in mind that Python 2.x is going away. This is not official but plan for January 1, 2020 as the drop dead day. This means where possible develop for Python 3. IMHO it is time to stop developing for AWS in Python 2.x.
If you have choco installed the following will work....
choco install -y awscli
$env:Path += ';C:\Program Files\Amazon\AWSCLI'
I am researching possibility to upgrade to Python 3.6 in our project.
Right now we are using Python 3.5.2 from ppa:fkrull/deadsnakes on Ubuntu 14.04. The PPA doesn't have Python 3.6 yet and it's not clear when it will be available.
I don't want to install yet another PPA.
And I am trying to find a more general approach.
I found people suggesting to use pyenv which compiles Python from source, which sounds interesting, because I can upgrade Python any time without waiting until repo maintainer adds it. Also I can easily install other Python flavors like PyPy.
I am not ready to use pyenv as virtual environment yes, so I am wondering if it's possible to use it to compile and install Python globally so that I can just use it.
The documentation is a little confusing because there is no python-build binary added in PATH after installation.
python-build is a pyenv plugin (installed by default). Documentation and more info is here: https://github.com/pyenv/pyenv/tree/master/plugins/python-build.
How to install system-wide Python for all users: 1) Login as root and 2) install required Python version to /usr/local/python-X.Y.Z.
sudo ~/.pyenv/plugins/python-build/bin/python-build 3.6.1 /usr/local/python-3.6.1/
Now you can use this Python version as a normal user, for example you can create virtualenv for your project:
/usr/local/python-3.6.1/bin/python -m venv /var/www/my-app/.env/
https://github.com/yyuu/pyenv/wiki/Common-build-problems#installing-a-system-wide-python
Installing a system-wide Python
If you want to install a Python interpreter that's available to all
users and system scripts (no pyenv), use /usr/local/ as the install
path. For example:
sudo python-build 3.3.2 /usr/local/
I've contributed a package for python3.6 in deadsnakes for trusty / xenial :)
https://launchpad.net/~fkrull/+archive/ubuntu/deadsnakes/+packages?field.name_filter=python3.6&field.status_filter=published&field.series_filter=
By combining the hints from the other answers and reading through the documentation, I found a nice way to do exactly what you want that should work well in a CI system or in a Docker container or on a developer machine if they haven't already installed python3.x via Apt or Yum or Homebrew.
Assuming you have all the dependencies required to build your desired version of Python 3.x (anything above 3.4 requires some extra packages the pyenv-installer doesn't always warn you about), you can run the commands below to get a new system wide Python that should be executable by all users, which makes it easy to pass to virtualenv creations with python3.6 -m venv yourvenv.
curl https://pyenv.run | bash # or
wget -O - https://pyenv.run | bash
export PATH="$HOME/.pyenv/bin:$PATH"
$(pyenv which python-build) 3.6.10 /usr/local/
which python3.6
python3.6 --version
# If you get an error running the above commands, it probably means
# /usr/local/bin isn't in your PATH yet
# on Debian/Ubuntu and maybe others the /etc/environment or
# /etc/login.defs file puts it in the path when a user logs in
echo $PATH
export PATH="/usr/local/bin:$PATH"
python3.6 --version
I am new to TeamCity and I do not know how to install packages I have imported in my python code on the TeamCity server. For example I have imported selenium in my code and tried to install it using command line on TeamCity by pip install selenium but I got the error pip: command not found. I am not sure this is the best way to install needed packages.
It seems like you don't have "pip" (Python package manager) installed on the machine that your Team City agent is running on. Team City does nothing but triggering your builds. In your case, it probably is only resolving dependencies (your Python packages) and running your code.
So you need to install pip on the machine that is running the Team City agent. (You might have multiple agents, install pip on all agents that might build this python project)
You might want to upgrade your Python. Python 2.7.9 and later already comes with pip. https://www.python.org/downloads/
Instruction on how to install pip.
https://pip.pypa.io/en/latest/installing.html
You can SSH to that machine and run the following bash script (assuming you are on UNIX).
$ curl https://bootstrap.pypa.io/get-pip.py >> get-pip.py && sudo python get-pip.py
There does not seem to be any documentation on how to do it. I went into /sdk/installer and ran the vboxsetup.py script but it raised the following exception:
Exception: No VBOX_INSTALL_PATH defined, exiting
It is really annoying that they don't adequately explain how to install it and it's weird that the virtualbox installation does not create the VBOX_INSTALL_PATH variable by itself.
Anyways, This is what worked for me:
export VBOX_INSTALL_PATH=/usr/lib/virtualbox
sudo -E python vboxapisetup.py install
this is a minimal example for running the Python demo script vboxshell.py from the VirtualBox SDK via the Object Oriented Web Service for Python.
Tested with:
System: macOS 10.15.2
VirtualBox version: 6.0.14
Instructions:
install VirtualBox for macOS
download SDK from the VirtualBox website (i.e. https://download.virtualbox.org/virtualbox/6.1.0/VirtualBoxSDK-6.1.0-135406.zip) and extract to $HOME/vboxtest/sdk
mkdir $HOME/vboxtest
create a python2 venv:
cd $HOME/vboxtest
virtualenv venv_vbox -p python2
source venv_vbox/bin/activate
install dependencies into the venv:
wget https://netix.dl.sourceforge.net/project/pyxml/pyxml/0.8.4/PyXML-0.8.4.tar.gz
pip install PyXML-0.8.4.tar.gz
pip install ZSI
disable auth (for testing): VBoxManage setproperty websrvauthlibrary null
install SDK python module:
cd $HOME/vboxtest/sdk/installer
export VBOX_INSTALL_PATH=/usr/local/bin/virtualbox
export VBOX_SDK_PATH=$HOME/vboxtest/sdk
python vboxapisetup.py install
start API webserver: /Applications/VirtualBox.app/Contents/MacOS/vboxwebsrv -t 0
start the actual demo script:
cd $HOME/vboxtest
source venv_vbox/bin/activate
cd $HOME/vboxtest/sdk/bindings/glue/python/sample
export VBOX_INSTALL_PATH=/usr/local/bin/virtualbox
export VBOX_SDK_PATH=$HOME/vboxtest/sdk
python vboxshell.py -w
You should be getting a virtualbox shell, in which you can i.e. list all vms:
$ python vboxshell.py -w
Running VirtualBox version 6.0.14
vbox>
vbox>list
Machine 'tmp_default_1572559409192_87222' [32844f81-f971-42f8-99d8-f3edbf0bf637], machineState=PoweredOff, sessionState=Unlocked
Machine 'c4-2' [891a3509-fbc5-44be-816d-5045dd626157], machineState=PoweredOff, sessionState=Unlocked
vbox>
For more infos check the SDK docs: https://download.virtualbox.org/virtualbox/SDKRef.pdf
(IMHO should be used with caution as both Python2 and ZSI are EOL).
Five years later, things haven't progressed much it seems.
Under Mojave, I had brew installed python2 (2.7.15) and python3 (3.7.0), and I had to do the following:
cd /Applications/VirtualBox.app/Contents/MacOS/sdk/installer
sudo VBOX_INSTALL_PATH=/Applications/VirtualBox.app/Contents/MacOS /usr/local/bin/python2 vboxapisetup.py install
sudo VBOX_INSTALL_PATH=/Applications/VirtualBox.app/Contents/MacOS python3 vboxapisetup.py install
The built-in Mojave version of Python (/usr/bin/python version 2.7.10) was the only one that could import vboxapi after the VirtualBox install. I had to add the other Python versions manually.
The only instruction regarding this that I could find comes on page 40 of the SDK ref, where it suggests:
# cd VBOX_INSTALL_PATH/sdk/installer
# PYTHON vboxapisetup.py install
But, of course no mention of an environment variable. As Tal points out in the accepted answer, interesting that they can be bothered to write a 440 page SDK manual, and yet fail to mention this.
Simple approach using virtual environs
I try to only use python 3. For pyvbox API on Mac OS I'm using a second virtualenv which is python 2 Python2 venv
Base set up:
cd /Applications/VirtualBox.app/Contents/MacOS/sdk/installer
export VBOX_INSTALL_PATH=/Applications/VirtualBox.app/Contents/MacOS
sudo -E python3 vboxapisetup.py
cd $HOME
mkdir vbox
virtualenv -p /usr/bin/python venvpy2
source venvpy2/bin/activate
pip install virtualbox
I still pretty much only use python3, then use subprocess.Popen initialise venvpy2 and run python2 module. Take stdout and stderr back into main controlling python3 code. Having got this to work, I've concluded better approach for my use case is use command line vboxmanage Automate box server setup