The Jenkins ShiningPanda plugin provides a Managers Jenkins - Configure System setting for Python installations... which includes the ability to Install automatically. This should allow me to automatically setup Python on my slaves.
But I'm having trouble figuring out how to use it. When I use the Add Installer drop down it gives me the ability to
Extract .zip/.tar.gz
Run Batch Command
Run Shell Command
But I can't figure out how people us these options to install Python. Especially as I need to install Python on Windows, Mac, & Linux.
Other Plugins like Ant provide an Ant installations... which installs Ant automatically. Is this possible with Python?
As far as my experiments for jenkins and python goes, shining panda plug-in doesn't install python in slave machines in fact it uses the existing python library set in the jenkins configuration to run python commands.
In order to install python on slaves, I would recommend to use python virtual environment which comes along with shining panda and allows to run the python commands and then close the virtual environment.
(This is a Windows-only answer. Perhaps someone can complement this with a Linux/Unix answer, which is probably even simpler.)
Here is how we're currently doing automatic Python installations on Jenkins, with the ShiningPanda Jenkins plugin, for Python 2.7 on Windows, installing to c:\Python27:
Download the Python Windows MSI installer from https://www.python.org/downloads/windows/, and put it on some central share.
If you're running a server-version of Windows, then make sure to set DisableMsi to 0, i.e., find or create registry key HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\Installer and create a value called DisableMsi and set it to zero.
On Jenkins => Manage Jenkins => Global Tool Configuration, add a 'Python installation', choose 'Install automatically' and set the label to cover all agent systems to which this applies. Then choose 'Run Batch Command', and as batch command use something like this:
if not exist c:\Python27\python.exe (
start /wait msiexec /qn /i \\some-central-system\some-share\python-2.7.14.amd64.msi /l*v python27-install-log.txt
)
as shown in the following screenshot:
(Notes on how this works: msiexec is the tool to run an MSI installer where '/i' means "install", and in the case of Python it does not require elevated permissions. /l*v does verbose logging. /qn is to make sure no UI is shown, and cmd.exe's start /wait makes sure that msiexec /i waits until the installation completes.)
That's it!
All of the above might very well work with other versions of Python as well.
Related
I feel uncomfortable using cmd and I want to use commands for my python scripts, wondering if there is any way to not use cmd for os.system() and instead changes that to my ubuntu terminal. Thanks!
Per the Python docs, os.system(<command>) executes <command> in a subshell, which is system dependent. There is no way to make os.system() run a Windows specific command as a Unix equivalent. You may be interested in Python's sys module
If you edit your question with more specific details as to what commands you are trying to run I might be able to provide better help.
os.system() normally runs system commands depending the OS you are running the script.
However, you can read this article on Stackoverflow or try to follow further steps to setup an effective environment for Python on Ubuntu on Windows.
Install Bash on Windows
Check for updates
Check out the REPL
Install Pip
Install VirtualEnv
Install VirtualEnvWrapper
Create your first virtualenv
Configure bashrc to keep it working
More detailes here
Rather than installing a version from python.org, I would like to have the CMD use Spyder 5's python installation.
I have done some digging and as I understand it I need to add python to the "Path" variable of my windows system. After adding the python.exe path C:\Program Files\Spyder\Python\python.exe and also trying C:\Program Files\Spyder\Python to "Path" in Environment Variables it made no difference and I receive the basic error:
> Python was not found; run without arguments to install from the
> Microsoft Store, or disable this shortcut from Settings > Manage App
> Execution Aliases.
As an additional detail I can open python scripts outside of Spyder after having selected "open with" and then selecting the python.exe file which is located in: C:\Program Files\Spyder\Python\python.exe. This is great but I definitely want to be able to run scripts from the CMD. I have also looked at C:\Users\Tech\AppData\Local\Spyder after looking at some my python installations my other machines but no python executables are saved there.
I have gone ahead and become well versed in how to setup virtual environments. I now set up virtual environments with the necessary libraries I need and simply have spyder use those. This works best for me as I can use easily install libraries that I need and switch environments if necessary. As plus for I can run the scripts in the command prompt easily which was the first issue that I ran into.
Spyder needs additional libraries installed to run with a custom virtual environment. On the first running it will crash and provide the pip command to install the necessary libraries.
I'm still improving my working knowledge of how to manage paths and environments. For now this works well for me and seems to be a step in the right direction.
I have decided to dabble my toes in using Anaconda in addition to pip, mainly so I can install Github's hub wrapper for git.
When I installed Anaconda, one of the prompts asked if I wanted to add Conda to the PATH variable, and recommended against NOT doing that, so I didn't.
I'd like to continue using Git Bash, as it is the only terminal interface I know how to use, and don't currently want to learn how to use the terminal that Anaconda provides. I did not fully understand the warning's explanation:
Not Recommended. Instead, open Anaconda3 with the Windows Start menu and select "Anaconda (64-bit)". This "add to PATH" option makes ANaconda get found before previously installed software, but may cause problems requiring you to uninstall and reinstall Anaconda.
I'm rather new to developing actual software, and pretty much do everything exclusively in Python in PyCharm on Windows, only occasionally using the terminal. That is changing fast however.
I'd like to know how likely these problems are in my case, under what conditions this will cause issues, and basically whether I should heed the warning or not.
Edit As a point of interest, Anaconda literally disappeared from my machine completely when I added it's directory to PATH. It left behind the terminal, which itself could not find conda when I did conda --version or where conda.
Heed the warning, don't add the anaconda path to %PATH%. There may be commands with similar names. Just use the anaconda cmd line prompt. When I use the anaconda prompt I just use 4 commands
python ...
taskkill /f /im python.exe - kill python programs when they hang up
dir -- same as git bash
cd -- same as git bash
You can always type help to see what other built-in windows commands are available or follow the command name with /? to find out what the parameters are. A bit like man pages on unix.
If you look at the anaconda prompt, what it does is
%windir%\System32\cmd.exe "/K" C:\ProgramData\Anaconda3\Scripts\activate.bat C:\ProgramData\Anaconda3
The problem with just using git bash is it only knows about its own little world and nothing outside it. It is just a way of bringing in *nix tools to Windows for the people who are accustomed to *nix commands can't be bothered to find out what the windows equivalents are (sometimes there aren't any).
Some of the commands (like ln -s) don't work. Since git bash is a *nix prompt, it does not understand windows commands so it won't be able to use this. The only other way is to use the anaconda command prompt. It is a windows command line. If you just wish to type pip and conda commands, the anaconda cmd prompt has been set up to run them. You don't need to learn anything else.
I'm new to pycharm, virtualenv, linux and git.
I've recently begun a journey of using djangoto make webapps. Before I used sublime to make scripts however now a more complex project management system such as pycarm was needed. I actually wanted to get a linux VM and go down that road but was advised that windows python IDE such as pycharm would be suitable
I recently learnt the importance of dependencies and how to use virtualenv. However in this tutorial, under the 'How do I use my shiny new virtual environment?' it starts using commands such as:
ls env
and
which python
Neither of which my pycharm console would understand.
I could use a console emulator such cmder to use the commands but then I would remove the convience of using the IDE's integrated one.
Should I upgrade to a linux VM ? Or can I install a package that allows me to use such commands in PyCharm.
As a bonus question, what are the commands in that tutorial ? are they linux commands? when ever i see $ .... is that the linux console ?
You can accomplish this using Vagrant: https://www.vagrantup.com/
You can use Vagrant and VirtualBox to setup a Linux VM (distro of your choice) and then install all of your Python dependencies in the VM. Once you have that setup, you can tell PyCharm to use the Python interpreter in your VM by following these steps:
Open the project settings dialog box in PyCharm.
Expand Project: (your project name) on the left side.
Click on Project Interpreter.
Click on the cog icon on the upper right side of the window and select Add Remote.
Click on the Vagrant radio button.
In the Vagrant Instance Folder box, select the directory your Vagrantfile is located in.
In the Vagrant Host URL box, make sure ssh://vagrant#127.0.0.1:2222 is specified.
Click OK.
Since Vagrant is compatible with Windows this solution should work for you. I have done it successfully using macOS and it works great. Good luck!
You might find this tutorial useful: https://developer.rackspace.com/blog/a-tutorial-on-application-development-using-vagrant-with-the-pycharm-ide/
I got this to work on Windows 10 with Anaconda Prompt. This terminal which comes with Anaconda, creates a "base" environment with a linux-like virtual machine and your Windows file system (C:\\) mounted to /c, and has bash installed with common Unix commands like cd, ls, chmod, echo, cat, ... Running programs from bash with access to environment variables is much nicer than Windows Powershell etc.
Now to get your Terminal in Pycharm to use Anaconda Prompt instead of cmd.exe, I followed this answer. After installing Anaconda and/or Anaconda Prompt, right-click -> Open File Location -> right-click the shortcut -> Properties -> copy file path. Then use your file path instead.
Conda is great for package environment management. Learn more about it here. For Django + Conda specifically, read here. You can also use pip to install from Python package indexes, github repos, and requirements.txt files instead. Unless you know how Anaconda Prompt works, I don't recommend creating your own environments from scratch. What worked for me was:
(base) C:\Users\wassadamo> conda create -n mynewenvironment --copy base
...
(base) C:\Users\wassadamo> conda activate mynewenvironment
(mynewenvironment) C:\Users\wassadamo> ls
folderA folderB file.txt
Works!
Whenever I try running conda deactivate to leave the base environment, my bash commands would stop working. So clone base as above.
Another tip: if you want to run shell scripts from Terminal within PyCharm with Anaconda Prompt this way, then execute them (e.g. "run.sh") on command line with
bash run.sh
I tried putting this on the first line of my run.sh
#!/usr/bin/bash
And running it with
./run.sh
But this had the effect of running it in an external Anaconda Prompt instance (add sleep, or some user input command to force it to wait and see for yourself). Explicitly running my .sh files with bash had the desired effect of running them in the same shell as I started them in PyCharm Terminal configured with Anaconda Prompt.
To use the SVN API with a Python script is it enough to have TortoiseSVN installed or do I need another SVN client?
I am using the cmd line features of tortoiseSVN but I'm looking for more advanced possibilities to work with SVN and wonder if I need to install another SVN client or so..
Thanks, Martin
Unless you're going to shell out to run a command-line program from within Python, you should be using PySvn or the "Subversion for Windows" distribution which includes Python libraries.
If you still want to run a command-line program from your Python script, use either the svn.exe that comes with the TortoiseSVN installation, or the one from the above-referenced Subversion for Windows. The TortoiseSVN command-line program (TortoiseProc.exe) is not intended to be used from within other scripts/programs like you describe.