I am creating a setup from C# program successfully with Inno Setup. To run this program I need Python. Until today I asked my customers to install Python manually, since some customers are not always following my installation guide, I am getting often questions from them. Now I want to simplify the installation, so that everything is done automatically. I need to set:
Install path of Python: C:\Python\Python3.5.2
Installation for all users
Set the global environment variable for Python C:\Python\Python3.5.2
If all this already exist no installation needed
I tried to do this with this code, but I didn't had any success. Normal Python installation is starting unfortunately.
[Run]
Filename: "{app}\deploy\python-3.5.2.exe"; \
Parameters: "/i ""C:\Python\Python-3.5.2"" /qb! ALLUSER=1 ADDLOCAL=ALL"; \
WorkingDir: "{app}\deploy"; Flags: 32bit; Check: python_is_installed
[Code]
function python_is_installed() : Boolean;
var
key : string;
begin
{ check registry }
key := 'software\Python\Python-3.5.2\InstallPath';
Result := not RegValueExists(HKEY_LOCAL_MACHINE, Key, '');
end;
What do I do wrong?
BR
Stefan
You seem to be using a completely wrong sent of command line arguments (for Windows Installer?).
See Python documentation for correct command-line arguments of the Python Windows installer:
https://docs.python.org/3/using/windows.html
You probably want something like this:
/passive InstallAllUsers=1 TargetDir=C:\Python\Python3.5.2 PrependPath=1
Another problem is that the installation check in the code section is not working as expected. RegValueExists() always returns false with an empty value name. That means your check function always returns false even if the key exists. This is the reason why Python installation is run always, even if Python is already installed.
To check for the existence of a key, not a value, use the function RegKeyExists().
See How to check if specific Python version is installed in Inno Setup?
Related
I am aware that similar questions have been asked before, but I either don't understand the answers, or there aren't any; so I decided to describe my problem in as much detail as possible.
Problem:
RStudio reticulate package uses Python from this path:
"/usr/bin/python"
but I want it to use python from this path - always, as a default:
"/Library/Frameworks/Python.framework/Versions/3.7/bin/python3"
How do I know it happens?
I open RStudio, and create a new python script. A new file with an extension .py is generated. I type something in:
import pandas as pd
and execute (by clicking cmd+enter). I then see what happens in the console - the reticulate package is called:
reticulate::repl_python()
Python 2.7.10 (/usr/bin/python)
Reticulate 1.12 REPL -- A Python interpreter in R.
I would like to permanently change where the reticulate package looks for Python.
From the Terminal I know:
$ python --version
Python 3.7.3
which python3
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3
So, I would like to tell RStudio to always look in this path to find Python 3.7. I have tried to use the following command, run from an R script:
use_python("/Library/Frameworks/Python.framework/Versions/3.7/bin/python3")
but it doesn't do anything - my naive understanding is that this command is useful within an R markdown file, i.e. when I have code that combines R and Python, in separate chunks. I would like to change the path that is used when a Python script is run from within RStudio. Is there some kind of a config file I could edit?
I hope this makes sense. I am not a regular Python user, only started learning now, and I am also not very good with paths, so I would appreciate step-by-step answers.
OK, so I have posted too early - after some more googling I can solve this problem myself, but I think it is worth posting an answer here for people like me (i.e. not path-proficient or python-proficient).
There is something like a config file for R, called .Renviron. In order to access it, use Terminal to go to your home directory (i.e. the one that you go to when you type 'cd'). If you have never used this file before, it might not exist, in which case you need to create it.
Once in your home directory, type:
ls -a
then check on the list of files that appears whether .Renviron is there. Below are instructions what if you already have .Renviron (IF YES), and what if you don't (IF NO).
IF NO, type:
touch .Renviron
which creates the file.
IF YES, just proceed as below (without using the touch command).
Write:
nano .Renviron
the .Renviron file will open. In it, add a line that says:
RETICULATE_PYTHON="enter your desired path here"
so, in my case, this is:
RETICULATE_PYTHON="/Library/Frameworks/Python.framework/Versions/3.7/bin/python3"
now save the file by exiting nano (ctrl+x) and clicking 'y' when it asks whether to save changes (press 'y' then press enter).
restart you RStudio. It should work now. I hope this is useful!
I recently found a fix for Python getpass not working on Windows: Python not working in the command line of git bash
Or at least that was the last thing I remember about changing my python configurations. (This is for Python 3.6.1 on Windows 10)
Now I also use Python to other tasks which simply has subprocess calls to type several commands on terminal:
go build ./folder/
mv ./src/ ./bin/
I get the error: go: GOPATH entry is relative; must be absolute: "/c/Users/OP/work". But I don't get it if I type go build ./src/folder myself.
I have GOPATH set to C:\work in Environment Variables. I have tried with a ;.
Is there a way to reverse the alias python every time? Or what is happening exactly when setting an alias for python to winpty?
I'm thinking that when I call go build directly, it is called by either my user profile or system. And when python's subprocess calls it, it calls the opposite. Therefore, I have two GOPATH variables even though I have only 1 set in environment variable.
Side Note: another recent change on GOPATH was changing it from C:/go because it couldn't be the same as GOROOT. That error popped up randomly for some reason. It worked with that setting for a while and I don't remember changing anything before except adding another import package on top of the many other ones already being used.
Update: with type python I get the result: python is aliased to 'winpty python.exe'. Therefore I tried to undo that with unalias python. The new result I get is: python is hashed (/c/Users/OP/AppData/Local/Programs/Python/Python36/python).
This fixed the go build command within Python's subprocess. However, that alias was a fix for another Python issue with using getpass package.
On top of my unalias python fix, I also discovered something interesting: when I change the environment variables for GOPATH from C:\work; to C:\go, all go commands still spit the error go: GOPATH entry is relative; must be absolute: "". I got this same error (but different path) from updating Windows 10 Fall Creators update. Maybe it is related.
Simply closing MINGW and reopening it fixed the issue. So perhaps it was saying a copy of my environment variables and using that as a reference instead of the actual system properties.
I know this is not a popular question, but someone could benefit from my hours of investigating and debugging.
Under Windows you must use a Windows style GOPATH like eg d:\code and probably you should use cmd shell and nothing else. Unfortunately cygwin paths (and probably others too) do no longer work especially for go get reaching out to git.
Stick to Windows paths and Windows shell.
The system will have a possible Python version of 2.4.5 or 2.7.9 only. I'm trying to write a batch error handling to try use python 2.7.9 first, and if that fails, use python 2.4.5.
Conditions
System has company installed software and will only have Python 2.4.5 or Python 2.7.9. And I won't know which one, so my scripts have to be backwards compatible.
This is what I have
rem
#echo off
echo Building
"%COMMONPROGRAMFILES%\CompanyName\python\python27\python.exe" build.py
IF ERRORLEVEL 1 GOTO TRY-PYTHON-24
IF ERRORLEVEL 0 GOTO FINISHED-BUILDING
:TRY-PYTHON-24
"%COMMONPROGRAMFILES%\CompanyName\python\python24\python.exe" build.py
IF ERRORLEVEL 0 GOTO FINISHED-BUILDING
:FINISHED-BUILDING:
echo Done
...more code...
Expected Result
Try and use Python 2.7.9 first, if there is ERRORLEVEL 1, then try Python 2.4.5. There won't be an error there. Is this the correct way of writing a batch version of try except statement like Python?
Such as..
try:
...Python 2.7.9...
except:
...Python 2.4.5...
Sources
I wrote this based on Microsoft's guide (https://support.microsoft.com/en-us/kb/39585). But I'm unsure if this is the best method to a try except on two versions of Python.
I can't speak to the general case of try-except constructs in batch files, but there is a much simpler way to solve this particular problem: use the PATH variable. The code shown can be replaced with
#echo off
set "PATH=%PATH%;%COMMONPROGRAMFILES%\WatchGuard\python\python27"
set "PATH=%PATH%;%COMMONPROGRAMFILES%\WatchGuard\python\python24"
python build.py || exit /b
rem ... more code ...
Setting PATH this way makes the batchfile interpreter automatically look for python.exe in both of the directories where it could be. If both versions of Python are installed, it will take the one earlier in the list, i.e. the one in ...\python27. (Note that this means if there is some other version of Python installed in a directory that already appeared in PATH when the script was invoked, that one will be used. This is probably what someone who set their system up that way wants.)
you can use IF EXIST :
set "p279="%COMMONPROGRAMFILES%\WatchGuard\python\python27\python.exe""
set "p245="%COMMONPROGRAMFILES%\WatchGuard\python\python24\python.exe""
if exist %p279% (
set "python=%p279%"
) else (
set "python=%p245%"
)
call %python% build.py
I am quite new with configuring Jenkins or Python but I have to set up a unitary test in Jenkins. My program is in Python, but only works on Python 2.6 whereas the Jenkins version I should be using is 2.7, so I'm trying to set up Jenkins to set some environment variables so that it prepares launching the accurate Python for that specific test (it is part of a greater project that will successfully run several other tests that work well).
The idea I had was to set in the command to execute several environment variables like PATH, LD_LIBRARY_PATH and PYTHONPATH such as following in the "Execute shell" command line interpreter:
PYTHONPATH=/path/to/python2.6/lib:$PYTHONPATH
PATH=/path/to/python2.6/bin:$PATH
LD_LIBRARY_PATH=/path/to/python2.6/lib:$LD_LIBRARY_PATH
... however, it was still calling the wrong version of Python. Therefore, I forced these variables to:
PYTHONPATH=/path/to/python2.6/lib
PATH=/path/to/python2.6/bin
LD_LIBRARY_PATH=/path/to/python2.6/lib
... and I still get errors because the old version of Python is called instead, even if it should not appear in the PATH ... It appears Jenkins will remember the location of the old libraries however and will try loading them first.
How would I correctly set the environment in a "subproject" in Jenkins so that I can call a different version of Python?
Thank you and best regards,
~Stéphane
If you want your program to run with a specific version of the python interpreter, you indicate it in the shebang
#!/usr/bin/python2.6
#your code here
What i did in my Jenkins shell script using a specific python version was something like this when calling my unit test:
python3 src/test/unit_test.py
I was using it to use Python 3.X but it should work with 2.6 as well using:
python2.6 src/test/unit_test.py
Stupid me... I was indeed doing things correctly, I just had a part of my code that was overriding the PYTHONPATH value, so the solution I had found previously was good.
FYI, I modified my shebang, if it's of any help to anyone ;)
I use Python 2.6 more than I use Leopard's default python installation, so I have it set as my main Python installation. But I'd rather use the default Python for a PyObjC program I'm working on. Is there any way to specify to only use it instead of Python 2.6?
Finally figured this one out myself. The key to this is to make the final executable link with /System/Library/Frameworks/Python.framework instead of /Library/Frameworks/Python.framework.
Try specifying the full path to the Python interpreter in the command line, something like:
/foo/bar/python2.6 script.py
/baz/python objcscript.py
You can also add a shebang to the beginning of your script (first line):
#! /foo/bar/python2.6 script.py
If you have the environment variable PYTHONPATH set, you might have to unset it or change it.
AFAIR this helped me (in main.m):
NSArray *pythonPathArray = [NSArray arrayWithObjects: resourcePath, [resourcePath stringByAppendingPathComponent:#"PyObjC"], #"/System/Library/Frameworks/Python.framework/Versions/Current/Extras/lib/python/", #"/Library/Python/2.5/site-packages", nil];
Also, make sure that this point to the Python installation you want to use (main.m):
Py_SetProgramName("/usr/bin/python");