"Bad" Python Install - python

I've been having issues with Python recently, such as compatibility with anaconda. When I ran Homebrew's brew doctor, I think I came across the problem, as laid out below. How can I wipe these files and do a clean install of Python?
Warning: "config" scripts exist outside your system or Homebrew directories.
`./configure` scripts often look for *-config scripts to determine if
software packages are installed, and what additional flags to use when
compiling and linking.
Having additional scripts in your path can confuse software installed via
Homebrew if the config script overrides a system or Homebrew provided
script of the same name. We found the following "config" scripts:
/Library/Frameworks/Python.framework/Versions/3.4/bin/python3-config
/Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4-config
/Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4m-config
/opt/local/bin/curl-config
/opt/local/bin/freetype-config
/opt/local/bin/libpng-config
/opt/local/bin/libpng16-config
/opt/local/bin/nc-config
/opt/local/bin/ncurses5-config
/opt/local/bin/ncursesw5-config
/opt/local/bin/pcre-config
/opt/local/bin/python2.7-config
/opt/local/bin/xml2-config
/Users/adamg/anaconda/bin/freetype-config
/Users/adamg/anaconda/bin/libdynd-config
/Users/adamg/anaconda/bin/libpng-config
/Users/adamg/anaconda/bin/libpng15-config
/Users/adamg/anaconda/bin/llvm-config
/Users/adamg/anaconda/bin/nc-config
/Users/adamg/anaconda/bin/python-config
/Users/adamg/anaconda/bin/python2-config
/Users/adamg/anaconda/bin/python2.7-config
/Users/adamg/anaconda/bin/xml2-config
/Users/adamg/anaconda/bin/xslt-config
/Library/Frameworks/Python.framework/Versions/2.7/bin/python-config
/Library/Frameworks/Python.framework/Versions/2.7/bin/python2-config
/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7-config
Warning: Python is installed at /Library/Frameworks/Python.framework
Homebrew only supports building against the System-provided Python or a
brewed Python. In particular, Pythons installed to /Library can interfere
with other software installs.

To uninstall using brew use this command brew uninstall <package>.
Mac OS X has python preinstalled so there is no need to install another Python instance unless it's necessary.
You can run brew install python to install Python using Homebrew.
Even though python is preinstalled as #jgritty hinted in comments, you may consider not to rely on it for development purposes.
So you should brew uninstall python then brew install python.
In order to remove an installed Python (2.7) instance, you need to run the following commands in your terminal;
sudo rm -rf /Library/Frameworks/Python.framework/Versions/2.7
sudo rm -rf "/Applications/Python 2.7"
remove the symbolic links in /usr/local/bin that point to this python version see ls -l /usr/local/bin | grep '../Library/Frameworks/Python.framework/Versions/2.7'
if necessary, edit your shell profile file(s) to remove adding /Library/Frameworks/Python.framework/Versions/2.7 to your PATH environment file. Depending on which shell you use, any of the following files may have been modified: ~/bash_login, ~/bash_profile, ~/cshrc, ~/profile, ~/tcshrc, and/or ~/zprofile.
A reference by #Ned Deily available at this link.

You can do brew list to see what brew has installed.
If python and python3 are not in that list, you may want to install either or both.
Based on these files:
/Library/Frameworks/Python.framework/Versions/3.4/bin/python3-config
/Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4-config
/Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4m-config
I would guess you ran a python 3.4 install downloaded directly from python.org or somewhere else.

Related

How do I replace a Python installed from source with a packaged version?

As Python 3.7 was being prepared I installed Python 3.7.0b3 from source. Now 3.7 is out and I want to use the version packaged for Ubuntu. So I've done
apt-get install python3.7
but
$ which python3.7
/usr/local/bin/python3.7
$ /usr/local/bin/python3.7 --version
Python 3.7.0b3
How does one uninstall a Python installed from source (on Ubuntu)?
Or how can I replace it with the apt repo packaged version?
Since you opened a bounty, I can't vote to close as a duplicate, but this question would seem to provide a possible solution. Quoting from the accepted answer:
You can use checkinstall to remove Python. The idea is:
Install checkinstall
Use
checkinstall to make a deb of your
Python installation
Use dpkg -r to
remove the deb.
checkinstall basically wraps a make install command and creates a Debian .deb package based on what was installed. Then, you can just uninstall that package to reverse make install completely. To be perfectly safe you may want to uninstall the packaged Python 3.7 first and reinstall it afterwards to avoid any conflicts (I wouldn't expect any, though, since the packaged version lives in /usr while your source version lives in /usr/local).
If you don't have your source files around anymore, you can always download them again (https://www.python.org/downloads/release/python-370b3/) and rebuild Python. Specifically, the checkinstall commands would look something like this:
sudo apt install checkinstall
wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0b3.tgz
tar xf Python-3.7.0b3.tgz
cd Python-3.7.0b3
./configure && make
sudo checkinstall -D --fstrans=no make install
sudo dpkg -r Python-3.7.0b3.deb
(-D creates a Debian package, --fstrans=no disables use of a temporary directory for installation).
Since I was also moving to python 3.7, I came across this question and decided to answer it, as well as finish my installation.
This are the two sources, which I used for installing python 3.7 on ubuntu 16.04:
https://askubuntu.com/questions/865554/how-do-i-install-python-3-6-using-apt-get
https://superuser.com/questions/241865/updating-python-on-ubuntu-system
Apparently from the first source the deadsnakes PPA contain Python 3.7 - Link: https://github.com/deadsnakes/python3.7/tree/ubuntu/xenial/Python
So following from my first source, I used the following commands to install Python 3.7:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python3.7
It installed Python 3.7 successfully but my Python 3.5.2 remains default. You can invoke/use Python 3.7 by running the commands:
python3.7 script.py
It works, so I decided to set Python 3.7 as default by removing python 3.5, but I came across my second source, and just decided to stick with using python3.7, when running my script in the terminal.
Apparently it says:
Ubuntu policies extensively for writing end-user software. So basically, a large part of the system is written in Python. To switch to Python 3.7, there needs to be done a piece of work consisting of updating and re-testing all the scripts.
So to say you can't just switch to Python 3.7 and delete the older version.
Also from a comment from my first source it states deleting the older version might break the system. I haven't been around to deleting my older version in case it might break the system, but since you are asking for how to download Python 3.7, I think my first source and the first part of my answer should to the work.
I hope it helps :)
It seems that your Python built from source is under /usr/local, and your PATH variable has /usr/local/bin before /usr/bin, since running python3.7 gets you the one under /usr/local rather than the packaged one which would be /usr/bin/python3.7.
Look at your PATH to verify this.
echo $PATH
(When you run a program in bash, that particular running bash instance will remember the location and not rescan the directories in the PATH for that program again, so it will not notice a new file that has appeared somewhere earlier in the PATH. You can prevent this by running hash -r to reset the cache or by just exiting the shell and launching it again.)
I presume your goal is for python3.7 (or any of the other commands provided by Python) to run the versions from your packaged install in /usr.
Unfortunately the python build process does not provide an uninstall method -- the only automated way to remove just the files installed by a source Python install requires using other tools ahead of time (such as checkinstall).
So you have some choices :
Change your PATH so that /usr/local/bin is after /usr/bin. To do this, edit your ~/.profile file or whatever other script you have configuring your PATH and logout/login. This will also affect any other commands you run that are available in both /usr/local/bin and /usr/bin.
Remove /usr/local and reinstall anything else you want there. If a Python install is the only thing in your /usr/local, or if you can easily reinstall anything else you had there, this might be the way to go.
Painstakingly figure out what files under /usr/local/bin were part of Python and remove them. You might be able use the corresponding files in /usr/bin from your installed python3 packages as a starting point to figure out the similar names for /usr/local/bin.
One-liner to get the list of files in /usr/bin from installed python3* packages:
$ for pkg in $(dpkg -l 'python3*' | grep '^ii' | cut -f 3 -d' '); do dpkg -L $pkg | grep '^/usr/bin/'; done | sort
This should produce a list of files like:
/usr/bin/2to3-3.x
/usr/bin/chardet3
...
(I've tested this one-liner on Debian, I'm not sure if any changes are required for Ubuntu)

Attempted install of Python 3 via homebrew fails on Mac OS X Sierra

I'm trying to install Python 3 alongside 2.7 with Homebrew but am receiving an error message I can't find a resolution to.
When attempting brew update && brew install python3 I get the following error:
Error: python 2.7.12_2 is already installed
To upgrade to 3.6.4_3, run `brew upgrade python`
I want to leave the python 2.7 installation alone so I can have both Python 2 & 3 accessible on my machine so I'm nervous that upgrading will overwrite the current 2.7 installation.
I figure I can still perform a clean side-by-side install with the package from python.org, but I want to know why I'm getting this homebrew error
brew doctor shows the following Warnings containing python
Warning: "config" scripts exist outside your system or Homebrew directories.
`./configure` scripts often look for *-config scripts to determine if
software packages are installed, and what additional flags to use when
compiling and linking.
Having additional scripts in your path can confuse software installed via
Homebrew if the config script overrides a system or Homebrew provided
script of the same name. We found the following "config" scripts:
/Library/Frameworks/Python.framework/Versions/2.7/bin/python-config
/Library/Frameworks/Python.framework/Versions/2.7/bin/python2-config
/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7-config
Warning: Python is installed at /Library/Frameworks/Python.framework
Homebrew only supports building against the System-provided Python or a
brewed Python. In particular, Pythons installed to /Library can interfere
with other software installs.
Warning: Some installed formulae are missing dependencies.
You should `brew install` the missing dependencies:
brew install python#2
To be honest, and what I also have on my own system, is Python 3 as the default and Python 2 available if I need it. With homebrew, you can just update your default as it wants you to do with the upgrade. That means when you run python, Python 3 will run as the default.
For Python 2, install brew install python#2. When you want to run Python 2, just run python2 in the terminal and you'll have it.
Python install will run once you fix the broken links by running brew link, and the missing link component.
These usually don't need SUDO, they will link then and run brew doctor once they have all been linked.

Install Python of specific version system-wide with pyenv

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

Installing python packages with no installation directory acces and no pip/easy_install/virtual_env

At work we have python installed, but no additional modules. I want to import some scipy modules but I have no access to the python directory for installation.
Similar questions have been asked on StackOverflow, but the answers always assumed easy install, pip or virtualenv were installed. At my workplace, none of these packages are installed. It's just the plain python installation and nothing else.
Is there still an option for me for installing modules in my local folder and calling them from python? If so, how do I go about it?
Not exactly installing modules on your local folder, but a solution nonetheless:
I used to work for a company that used windows and didn't have admin access, so I ended up using Portable python.
It seems portable python is no longer mantained, but you can see some other portable python solutions on their site, most of which you can run straight from your usb.
You can download pip from here http://pip.readthedocs.org/en/stable/installing/ and install it without root privileges by typing:
python get-pip.py --user
This will install to directory with prefix $HOME/.local so the pip executable will be in the directory $HOME/.local/bin/pip, for your convenience you can add this directory to $PATH by adding to end of .bashrc file this string
export PATH=$HOME/.local/bin/:$PATH
After this you can install any packages by typing
pip install package --user
Or you can alternatively compile the python distribution from source code and install to your home directory to directory $HOME/.local or $HOME/opt or any subfolder of $HOME you prefer, let's call this path $PREFIX. For doing this you have to download python source code from official site, unpack it and then run
./configure --prefix=$PREFIX --enable-shared
make install
And then add python binary to $PATH, python libraries to $LD_LIBRARY_PATH, by adding to the end of $HOME/.bashrc file whit strings
export PATH=$PREFIX/bin:$PATH
export LD_LIBRARY_PATH=$PREFIX/lib
and when after restarting bash you can also run
python get-pip.py
and pip and will be installed automatically to your $PREFIX directory. And all other packages those you will install with pip will be automatically installed also to $PREFIX directory. This way is more involved, but it allows you to have the last version of python.

How do I create a virtualenv environment in python 3.3 on centos when the main python on the system is 2.6.6?

The administrators will not provide sudo access and already installed pip and virtualenv but they are all based off of the 2.6.6 python they have installed on the main system and will not allow any changes. I have to do everything by building a virtualenv. When I build a virtualenv with their python it is only in 2.6.6 and only has 2.6.6 python executable. I need 3.3 to run my application. (I cannot install packages with yum either or do anything really writing to main areas that require sudo access) I tried building a version of python 3.3 in my home directory and then doing the following but then I have problems with missing zlib.
virtualenv py3 --python=/home/ted/p3/bin/python3.3 --no-site-packages --verbose
Then I tried to install pip separately with the python3.3 but similarly had zlib problems.
Also, I've seen the recommendations to just install zlib from other packages like ...
sudo apt-get install dpkg-dev
but I don't have access to yum to do that.
You absolutely don't need Superuser Privileges to create python virtual env.
Download python package from Active-Python Web site.
Download latest setuptools-.tar.gz and pip.tar.gz packages.
Extract ActivePython Package wherever you want.
cd ActivePython, and ./install.sh (enter) you have to enter a new folder path say vpython3
Now you got python installed, but its not virtual yet. now place downloaded setuptools.tar.gz and pip.tar.gz into vpython3/bin/
now fallow below: -
pwd
/home/hayathms/Softwares/vpython3
cd bin
./python3 virtualenv ../../vpy3
Above vpy3 folder has complete virtual enviornment. :)
So activating it is like this.
source /home/hayathms/Softwares/vpy3/bin/activate
Done!...

Categories