I am currently extending an existing installer based on WiX to deliver a Python API (let's call it PythonAPI) that was newly implemented for some software. I have added the necessary files to the installer and they are being placed in the appropriate position (say C:\Program Files\SomeSoftware\PythonAPI). I am able to install the API via pip with the command
python -m pip install "C:\Program Files\SomeSoftware\PythonAPI"
This allows me to select the python version for which I want to install the package by selecting the appropriate python interpreter. This package for example is only compatible with python3.6 and above.
My question is: How do I find installed python interpreters with the help of WiX and use the appropriate one to run the installation command above?
The simplest way would be to assume there is an appropriate python interpreter in the PATH, but I don't want to rely on that. Instead I assume it would be best to check the registry for keys like
HKLM\SOFTWARE\Python\PythonCore\versionnumber\InstallPath
HKCU\SOFTWARE\Python\PythonCore\versionnumber\InstallPath
where versionnumber is something like 3.6 to get the install path and use this absolute path to the interpreter. However if I understand the RegistrySearch feature of WiX correctly, it would be hard to scan for multiple versions (>=3.6) since I have to give the full key path (in this case including versionnumber). I could of course hard code checks for the currently available versions (3.6, 3.7 and 3.8) but this would mean I have to manually extend this every time a new python release comes along.
Once the correct interpreter is selected I would assume a CustomAction could be used to run the install command mentioned above.
Related
I'm building a VS Code extension that assumes that the user already has a particular Python package installed on their system.
What could be the possible approaches to install that Python package to the user's machine when the user installs my VS Code extension.
I was able to think of a few ways to do so but couldn't find any resources on the internet validating my approaches:
creating a subprocess from inside the VS Code extension and calling pip install if VS Code is allowed to make such a privileged install to the user's machine without having any special/admin rights?
adding that package as a dependency in the package.json so it gets installed when the user tried to install the extension? Is there a way to add Python packages as dependencies?
This doesn't sound like a good idea, because different users will use different Python versions and python environments. When you specify a specific Python version, is the cost of using the extensions you designed a little too high?
Moreover, with the update of Python version, your extensions also need to design new specific dependent versions.
I suggest that you try to let users customize as vscode recognizes Python interpreter, otherwise the applicable population will not too much.
How to package Python itself into virtualenv? Is this even possible?
I'm trying to run python on a machine which it is not installed on, and I thought virtualenv made this possible. It activates, but can't run any Python.
When setting up the virtualenv (this can also be done if it already set up) simply do:
python -m virtualenv -p python env
And Python will be added to the virtualenv, and will become the default python of it.
The version of Python can also be passed, as python uses the first version found in the PATH.
virtualenv makes it convenient to use multiple python versions in different projects on the same machine, and isolate the pip install libraries installed by each project. It doesn’t install or manage the overall python environment. Python must be installed on the machine before you can install or configure the virtualenv tool itself or switch into a virtual environment.
Side note, consider using virtualenvwrapper — great helper for virtualenv.
You haven't specified the Operating System you are using.
In case you're using Windows, you don't use virtualenv for this. Instead you:
Download the Python embeddable package
Unpack it
Uncomment import site in the python37._pth file (only if you want to add additional packages)
Manually copy your additional packages (the ones you usually install with pip) to Lib\site-packages (you need to create that directory first, of course)
Such a python installation is configured in such a way that it can be moved and run from any location.
You only have to ensure the Microsoft C Runtime is installed on the system (but it almost always already is). See the documentation note:
Note The embedded distribution does not include the Microsoft C Runtime and it is the responsibility of the application installer to provide this. The runtime may have already been installed on a user’s system previously or automatically via Windows Update, and can be detected by finding ucrtbase.dll in the system directory.
You might need to install python in some location you have the permissions to do so.
Some time ago when i wanted to install a package using Conda in Anaconda python distribution i saw that Conda wants to update the python package from 2.7.10-0 to 2.7.10-1. It's the same python version (2.7.10 in this case).
Checking the channel's content I see there are multiple packages for the same python version:
python-2.7.10-0.tar.bz2 18.3M
python-2.7.10-1.tar.bz2 16.7M
python-2.7.10-3.tar.bz2 16.7M
...
So what is the difference between these builds and how can i prevent them to be updated?
What you're seeing there are build numbers.
They're usually used to fix a build of the same version of a package.
For example, imagine you have built this python version accidentally as a pydebug build. However, that's not what you want since it will lead to crashes in users of this package if they're not away that this is a pydebug build.
In this case you should rebuild the package (correctly this time), increment the build number and re-upload it.
So what is the difference between these builds?
You can't easily know the difference, unless Continuum provides a changelog for each build of python they provide (which I sincerely doubt).
To install a package with a specific build number you could do: conda install "python=2.7.10 0". The 0 means the build number.
I don't know if this syntax is officially supported, however it worked the last time I used it.
how can i prevent them to be updated?
First I would have to know what is your workflow.
If you're asking about the command-line, I don't think that is possible.
If you're asking about using environment.yml files you can pin a package to a specific version (including the build number) using a similar syntax of conda install.
I'm currently doing some embedded systems programming. This was set up by somebody else a few years ago. So now I'm looking to upgrade to Python 2.7.2 to make things simpler because I have already run into two cases where what I coded wasn't supported.
What is currently running:
: uname -a
Linux host1 2.6.18-6-486 #1 Sun Feb 10 22:06:33 UTC 2008 i586 GNU/Linux
: python -v
Python 2.4.4
: pyversions -i
python2.4
So right now only 2.4 is installed.
I untarred python2.7.2 and when I go to that directory and run python27 setup.py install --home=/home/jhemilian and it seems like python2.4 doesn't seem to know the with...as statement syntax:
host1:/home/jhemilian/src/Python-2.7.2: python setup.py install --home=/home/jhe
milian
File "setup.py", line 361
with open(tmpfile) as fp:
^
SyntaxError: invalid syntax
Before I go figuring this out I first have a question: python itself is being used to install Python? What if I didn't have the first version of Python installed? I know it's shipped with most Linux but hypothetically -- how does such a seeming catch-22 like that work?
What I am looking to do is install python2.7 in a benign location, keeping the python command still as using Python 2.4 just in case the "legacy" software i'm running is dependent on it, and running python2.7 myscript.py et cetera when I want to run one of my newer scripts. Feel free to comment if there is a cleaner or more practical (or even safer!) way to do this.
I don't think it would make much sense to go replacing all the with statements with compatible try blocks. I've looked though the READMEs and online documentation but I can't seem to find a way to install Python without already having Python. Note that I DO NOT have internet connection, although if desirable or necessary I could. It would be great if somebody could point me in the right direction. Thanks!!
It's all right in the README...
You don't need to use python to install, in fact, you shouldn't...just:
./configure
make
make install
If you want to install in a specific dir, just follow what the README says:
Installing
To install the Python binary, library modules, shared library modules
(see below), include files, configuration files, and the manual page,
just type
make install
This will install all platform-independent files in subdirectories of
the directory given with the --prefix option to configure or to the
prefix' Make variable (default /usr/local). All binary and other
platform-specific files will be installed in subdirectories if the
directory given by --exec-prefix or theexec_prefix' Make variable
(defaults to the --prefix directory) is given.
If DESTDIR is set, it will be taken as the root directory of the
installation, and files will be installed into $(DESTDIR)$(prefix),
$(DESTDIR)$(exec_prefix), etc.
All subdirectories created will have Python's version number in their
name, e.g. the library modules are installed in
"/usr/local/lib/python/" by default, where is the
. release number (e.g. "2.1"). The Python binary is
installed as "python" and a hard link named "python" is
created. The only file not installed with a version number in its
name is the manual page, installed as "/usr/local/man/man1/python.1"
by default.
If you want to install multiple versions of Python see the section
below entitled "Installing multiple versions".
The only thing you may have to install manually is the Python mode for
Emacs found in Misc/python-mode.el. (But then again, more recent
versions of Emacs may already have it.) Follow the instructions that
came with Emacs for installation of site-specific files.
EDIT: virtualenv is apparently for already-installed Python versions. Disregard this recommendation.
I think what you want is virtualenv.
I haven't used it myself, but I understand this is what it's meant for.
From the website:
virtualenv is a tool to create isolated Python environments.
The basic problem being addressed is one of dependencies and versions, and indirectly permissions. Imagine you have an application that needs version 1 of LibFoo, but another application requires version 2. How can you use both these applications? If you install everything into /usr/lib/python2.7/site-packages (or whatever your platform's standard location is), it's easy to end up in a situation where you unintentionally upgrade an application that shouldn't be upgraded.
EDIT: Upon review, I think you want Alberto's answer, so I voted him up for visibility.
I am trying to create a .pkg installer for a python application (specifically Spyderlib). This is not an app but a python package and a command line executable that have to be copied to specific locations.
However, the location depends on the version of OSX. I'm only targeting 10.6 and 10.7 but they come with different versions of python (2.6 and 2.7) so the install path is different.
Using bdist_mpkg I was able to create a Mac mpkg in 10.7 which installs correctly and can be edited with PackageMaker. Now I want to know how I can edit this package so that it detects the version of OSX and sets the install target path correctly.
I understand that I can use shell scripts to do pre and post-installation jobs, however I haven't been able to find examples of how to do this and how a script could but used to set the install target for the files in the mpkg.
Alternatively, it may be that this is possible to do directly from PackageMaker, but i was not able to see anything to this effect (and the documentation seems quite superficial).
So I would like to know how this could be done. It would also be really helpful to see some examples for other software packages.
You don't need any scripts - you can do that with Package Manager alone - the Package Manager GUI allows you to tag packages as installable (enabled) and selected based on conditions such as OS version (in Choices under Requirements)