Using Enthought Python instead of the system Python - python

I've installed the Enthought Python Distribution, which is basically a glorified Python distribution with added libraries for numerical and scientific computing. Now, since I use Debian, there is Python installed already. If I wish to use the Enthought Python for all work, how would I go about doing that?
Right now I am using a rudimentary alias like:
alias python='/usr/local/share/enthought/bin/python'
This is fine, but fails for shebang directives like #! /usr/bin/env python in independent Python scripts. So how do I get the system to use Enthought Python (without breaking anything of course!). Thanks!

I think this is the official way of doing it, as recommended by Enthought:
export PATH=/usr/local/EPD/bin:$PATH
if you installed to /usr/local/EPD. Otherwise, the general form is
export PATH=/path/to/EPD/bin:$PATH
This prepends the path to the EPD binary directory to your system PATH variable. The : is some sort of concatenate symbol. You can either run this in terminal every time, or you can put this in your ~/.bashrc file.
Critical Edit:
It turns out that EPD should actually be appended to the PATH, or you may have OS problems. Do it like this:
export PATH=$PATH:/path/to/EPD/bin

If your on Debian you could install enthought Python in virtualenv.
Enthought would have its own libraries without bothering other debian programs that need the system version. You could make switching easier between environments with virtualenvwrapper.
There is also a method with virtualenv to share (certain) site-packages among environments. Make sure to use pip instead of easy_install within a virtualenv.
Django people do it all the time.

Symlink the current version of python to the Enthought one.
ln -s /usr/bin/python[version] /path/to/enthought/python

I think, that on Debian it is better to install packages like this:
apt-get install python-numpy python-numpy-doc python-scipy python-matplotlib ipython
instead of install Enthought Python Distribution.

Hmm I'm also encountering this problem. The first thing I did was the suggestion to prepend python to the path as suggested by Chad, but this results in some problems for other linux apps that use libraries that are not included in Enthought but are included in Linux Mint (or whatever distro you're using). In particular, if I load python from terminal, I successfully enter Enthought's version of python, but running "import pygtk" results in an error (because the library isn't installed in the Enthought version of python).
Does anyone know how to use PYTHONPATH to include first Enthought libraries, and then include the standard Linux libraries? This would be the optimal configuration....

I use aliases.
alias python=~/Softwares/EPD_7.3/epd-7.3-2-rh5-x86_64/bin/python
alias ipython=~/Softwares/EPD_7.3/epd-7.3-2-rh5-x86_64/bin/ipython

Related

macOS Big Sur; Command Line Tools and Python 3.8.2

I am experiencing difficulty with installing Python correctly on my Mac (Fresh Install, I wiped my PC clean). I installed firstly
Home Brew
Xcode through App Store
Command line tools using command: "xcode-select --install"
On typing the following command:
which python3
Output is as follows:
gaurangsmacbookpro#Gaurangs-New-MacBook-Pro ~ % which python
/usr/bin/python
gaurangsmacbookpro#Gaurangs-New-MacBook-Pro ~ % which python3
/usr/bin/python3
upon running the following command which I was following off a blog from this site:
https://www.pyimagesearch.com/2016/12/05/macos-install-opencv-3-and-python-3-5/
brew install eigen tbb
Home brew installed python 3.9 dependencies so no when I type the following commands:
brew list python3
I get the following output:
gaurangsmacbookpro#Gaurangs-New-MacBook-Pro ~ % brew list python3
/usr/local/Cellar/python#3.9/3.9.1_8/bin/2to3
/usr/local/Cellar/python#3.9/3.9.1_8/bin/2to3-3.9
/usr/local/Cellar/python#3.9/3.9.1_8/bin/easy_install-3.9
/usr/local/Cellar/python#3.9/3.9.1_8/bin/idle3
/usr/local/Cellar/python#3.9/3.9.1_8/bin/idle3.9
/usr/local/Cellar/python#3.9/3.9.1_8/bin/pip3
/usr/local/Cellar/python#3.9/3.9.1_8/bin/pip3.9
/usr/local/Cellar/python#3.9/3.9.1_8/bin/pydoc3
/usr/local/Cellar/python#3.9/3.9.1_8/bin/pydoc3.9
/usr/local/Cellar/python#3.9/3.9.1_8/bin/python3
/usr/local/Cellar/python#3.9/3.9.1_8/bin/python3-config
/usr/local/Cellar/python#3.9/3.9.1_8/bin/python3.9
/usr/local/Cellar/python#3.9/3.9.1_8/bin/python3.9-config
/usr/local/Cellar/python#3.9/3.9.1_8/bin/wheel3
/usr/local/Cellar/python#3.9/3.9.1_8/Frameworks/Python.framework/ (3019 files)
/usr/local/Cellar/python#3.9/3.9.1_8/IDLE 3.app/Contents/ (8 files)
/usr/local/Cellar/python#3.9/3.9.1_8/lib/pkgconfig/ (4 files)
/usr/local/Cellar/python#3.9/3.9.1_8/libexec/bin/ (7 files)
/usr/local/Cellar/python#3.9/3.9.1_8/libexec/pip/ (480 files)
/usr/local/Cellar/python#3.9/3.9.1_8/libexec/setuptools/ (334 files)
/usr/local/Cellar/python#3.9/3.9.1_8/libexec/wheel/ (44 files)
/usr/local/Cellar/python#3.9/3.9.1_8/Python Launcher 3.app/Contents/ (16 files)
/usr/local/Cellar/python#3.9/3.9.1_8/share/man/ (2 files)
The contents of my ~./bash_profile file are as follows:
# Add Homebrew's executable directory to the front of the PATH
export PATH=/usr/local/bin:$PATH
export PATH="/usr/local/sbin:$PATH"
export PATH="/usr/local/opt/python#3.8/bin:$PATH"
What am I doing wrong? I just want a fresh clean install of Python 3.8 not 3.9 as there is no support for TF Lite on 3.9 yet. Can someone help me fix this mess? I will be very grateful!
I'm a bit late at the game, but I hope this will be useful to somebody. The best solution here is to use a virtual environment, but for the sake of argument and because it is a little bit more involved, I won't discuss that as an option here and will assume you just want a specific version installed on your machine where you can just add all the dependencies you need.
From looking at the page OP was using, the easiest solution here is probably to use a distribution like Anaconda if you are particularly interested in OpenCV or that type of libraries. Then it's just a case of setting up your path like export PATH=$HOME/anaconda/bin:$PATH or whatever path you used to install Anaconda with your shell of choice.
But let's imagine that Anaconda doesn't help you and you still need a specific version of Python, and you figure 3.8.2 is good enough for your needs and a newer version wouldn't work. Using the Python version that comes with the Xcode command line tools is probably a bad idea, just like using the system installed Python is. That version is really meant to support the Apple toolchain and while I've never run into any issues with it, I would not recommend it.
Next option is is to use homebrew. Great option since most people will already be using it, and you might already have python installed as part of a dependency but maybe like OP it's not the version you were hoping for. You can still make it work by installing an older version like so brew install python#3.8 however, it comes with a few caveats. Whenever one of the python dependencies is updated, you might need to unlink and relink it so that you can continue to use the correct version. Believe me, it's no way to live.
What I've found works (in combination with virtual environments is to use pyenv. Install it through homebrew, set your shell as described in the install doc and use it to install the python version you want (very easy) and then set the global interpreter to be whatever version you want and your system will stick to it until you set it to something else. It also works great in combination with tools like pipenv which allow you to manage virtual environments.

Installing pip with default python on Mac OS 10.14 Mojave

I would like to install pip for the default installation of Python on Mac OS.
Please don't recommend brew, I already have it and installed Python 3 with it, but it seems that Automator only knows how to use the default version of Python located in /usr/bin/python That's the reason behind my specific request
I did my homework first, or tried to, before asking the question, but what I found confusing is that the recommended method seems to be using get-pip.py, but the pip documentation says
Warning Be cautious if you are using a Python install that is managed
by your operating system or another package manager. get-pip.py does
not coordinate with those tools, and may leave your system in an
inconsistent state.
This threw me off, as I don't want to risk breaking the default Python on Mac OS, as I understood that might mess my system.
I also didn't want to use the deprecated easy_install.
And I couldn't find an answer to my question, as usually the answers just recommend installing a different version of Python with brew.
Please don't recommend brew, I already have it and installed Python 3 with it, but it seems that Automator only knows how to use the default version of Python located in /usr/bin/python That's the reason behind my specific request
Can you possibly use "Run Shell Script" in Automator and specify the python version you want to use. See Specify which version of Python runs in Automator? and https://apple.stackexchange.com/questions/233890/calling-python-3-script-from-applescript
Problem
Seems like Automator isn’t loading /usr/local/Cellar/bin into your PATH. You can echo $PATH in Automator to confirm this.
Solution
Reinstall using brew and ensure that you run brew link python.
You can export PATH=... before running your script or move /usr/bin/python to /usr/bin/pythonx.x where x is the default version installed, then symlink /usr/bin/python to your brew installed python in /usr/local/bin/.

Use system python in homebrew

Is it possible to use system python in homebrew?
I have python 2.7.5 installed on my mac, but when I try to install any homebrew package with python in dependencies, it starts loading python 2.7.9.
It is important for me to use system python because of lots of installed python packages.
What version of python homebrew uses depends on two things:
Where the python alias points to.
What the python path is in the formula.
In most cases, homebrew forumlae simply use the python command, and does not specify a python path. If it does, then it is usually /usr/bin/python.
So, you can fix the problem in two ways:
Change the homebrew formulate to point to the right python interpreter of your choice.
Change where the python command points to.
The first option is problematic, since it means that you need to go into your Cellar folder, and alter things. This is not nice, and usually not required.
A better alternative is to point to the right python command. This is where pyenv comes in handy. pyenv is a command line tool that helps you manage different versions of python. Follow the instructions here:
https://github.com/yyuu/pyenv-installer
to install it.
Once that is done, change your python command to whatever version of python you'd like it to point to.

ipython for Python 2.7.2 users on PUIAS (RedHat) Linux

I am guessing that I am not the only one using non-system Python 2.7.2 for scientific computations on 6.2 PUIAS Linux (RedHat)). My Python 2.7.2 is installed in the sandbox and I call it with the command python2.7. When I need to execute scripts this is not the problem. However, I would like to use ipython instead default Python shell for interactive use. I added ipython using yum? When I start it, it defaults to system python. How do I force it to load python2.7?
Thanks a bunch!
IPython is a Python package. When you have multiple Pythons, you must (generally, barring PYTHONPATH hacks) install a package for a given Python. yum would only install it for the System Python, so you must install it separately for your own Python. The solution is to simply pip install ipython with your own Python (install distribute/pip first, if you haven't).
I am going to answer my own question. For people who are using Python for scientific computing on RedHat clones (PUIAS for example) the easiest way to get all they need is to use rpm package manager and Enthought Python Distribution (EPD for short). EPD installs everything in a sandbox so system tools which are based on an obsolete version of Python are not massed up. However, paths have to be adjusted for system or even easier on the user base so that the using shell invokes non-system tools.

How do I upgrade python 2.5.2 to python 2.6rc2 on ubuntu linux 8.04?

I'd like to how to upgrade the default python installation(2.5.2) supplied with ubuntu 8.04 to python 2.6rc2. I'd like to make 2.6 the default python version on the system and migrate all the other useful installed python libraries installed on 2.5.2 to python 2.6rc2. Please let me know how I can achieve this.
Thanks
Dirk
With the warning that I think it's a tremendously bad idea to replace the default Python with an unreleased beta version:
First, install 2.6rc2. You can download the source from the Python website. Standard ./configure && make && sudo make install installation style.
Next, remove the /usr/bin/python symlink. Do not remove /usr/bin/python2.5. Add a symlink to 2.6 with ln -s /usr/local/bin/python2.6 /usr/bin/python.
Once again, I think this is a terrible idea. There is almost certainly a better way to do whatever you're trying to accomplish.
Migrating installed libraries is a much longer process. Look in the /usr/lib/python2.5/site-packages/ and /usr/local/lib/python2.5/site-packages/ directories. Any libraries installed to them will need to be re-installed with 2.6. Since you're not using a packaged Python version, you cannot use Ubuntu's packages -- you'll have to manually upgrade all the libraries yourself. Most of them can probably be installed with sudo easy_install <name>, but some like PyGTK+ are not so easy. You'll have to follow custom installation procedures for each such library.
I have the same issue, and apparently pre-built binaries can be found here:
# Python 2.6
deb http://ppa.launchpad.net/doko/ubuntu intrepid main
deb-src http://ppa.launchpad.net/doko/ubuntu intrepid main
Is there any need to?
Ubuntu in general doesn't package RC releases. 2.6 will not be available in Ubuntu until Jaunty Jackalope.
However,, if you insist that you need to install it, then, you'll have to do so without a package manager.
Download the package, and unzip it to a directory
run the following commands (waiting for each to finish as you do so)
./configure
make
sudo make install
There, you have it installed.
It's better to wait for it to be packaged first, espescially as Python is used in a lot of ubuntu internals, so may break your system horribly
It would not be wise to change the default version of Python, i.e. what you get when you type "python" into a shell. However, you can have multiple versions of python installed. The trick is to make sure that the program named "python" on the path is the system supplied version. If you want to run your install of Python 2.6 you'd then type python2.6 into a shell to start it.
Download the package and unzip it, then run:
./configure
make
sudo make install
ls -l /usr/local/bin
You should see a python and a python2.6 file, both created on the day you ran make install; delete the python file. Then when python is launched the standard system Python version from /usr/bin will be run, and when python2.6 is run you get your shiny new python 2.6rc2. Python displays the version when it starts an interactive interpreter.

Categories