Is it safe to remove manually installed Python 2.7 from Yosemite? - python

I don't code but needed to use Python just for one simple task. That task specifically required a Python 2.x version. I've downloaded it from https://www.python.org/downloads/release/python-279/ and installed. Later, I wanted to remove Python, but learned that OSX has also Python 2.x preinstalled and removing it is dangerous. Is removing the one I've installed (i.e Python 2.7 package in my Applications folder) also dangerous? If not, why Finder asks me to enter my password to move those files to trash, which often required to make changes on system files?
Thanks

Removing the second Python you installed from python.org should be fine: follow the instructions at: https://docs.python.org/2.7/using/mac.html?highlight=uninstall
This Python puts itself in /Library/Frameworks/ and symlinks in /usr/local/bin/. You need admin privileges to remove things from these directories which is why it's asking for your password.
The system installation of Python is in /System/Library/Frameworks/ and /usr/bin/python. Don't mess with it because the OS needs it.
Having said that, unless you're really pressed for space, just leave things as they are and enjoy your life.

MAC OS X 10.9 (at least) and above already had python 2.7 installed, so you don't have to manually install one. Installing python and similar packages are not like what you did with your applications. So, if you are not familiar with UNIX or XNU concepts, don't remove it. It will not just remove some binaries, but also lots of library files. Asking password is because removing some library files would need higher privillege, and usually you don't have with normal account.
In a word, in your case, I suggest keep the python, and don't install new one. v2.7 is all you want.

Related

Is it ok to install both Python 2.7 and 3.5?

Supposedly Python 2.7 is included native to OSX 10.8 and above (if I remember correctly), but I recently installed Python 3.5 to use for projects while I work through UDacity. Lo and behold, the UDacity courses seem to use 2.7 - wups! So instead of trying to uninstall 3.5 (this procedure seemed to scary for neophytes such as myself), I simply installed 2.7 in addition to the recently installed 3.5 and just run the 2.7 IDLE and Shell. Is this ok, or will I run into problems down the road?
I have installed two versions, 2.7, 3.4 and I do not have any problem by now. 3.4 I am using for my work project in eclipse environment, 2.7 for udacity course, like You ;).
As long as you keep your installation folders organized, you should have no issues having both on your computer, besides one thing. The path environment variable for python will determine which version is used by default, so I would say stick to one version, or make sure to make your programs as backwards compatible as possible. I have run into this issue on Windows, since I installed Python 3.4 before 2.7, and therefore to run older code, I have to manually select the python executable. In terms of libraries, I believe that for each python version, the libraries are completely separate, so you should be good there.
As others have said, if the installation directory is different it should be no problem at all.
One thing that'll make your life easier for switching between the two is to use an IDE such as PyCharm, you just have to change a drop down to switch between the two versions.
It should be fine. Its actually pretty common to have multiple Python environments. It helps to prevent dependency conflicts between your projects. That is what is happening when you are using tools like pyenv and virtualenv.
Using tools like pyenv and virtualenv may also help you with the path problems that others mentioned. They have commands to set up the path so that their version of pip, python, etc are used.
Im not sure about OSX, but with windows 10 my environment variables for 2.7 were overwritten with the 3.5 path. Not a tough fix, but a little confusing, since it was months later when I needed 2.7 again.
You can also use Anaconda for maintaining two versions of Python:
Download Anaconda for both Python versions
Open .bashrc
Add the path to new Anaconda you have installed for, e.g.:
export PATH="/home/paras/anaconda3/bin:$PATH"
Now there will be 2 export paths: one for Python 2 and one for Python 3. Comment the one which you don't want.
I have the same problem and it is not necessary to uninstall on version of python. Please take care to not mix them up - When you search them up on the start menu. You can make a desktop shortcut saying 2.6 and 3.5.

portable python 3.x and pygame

I am looking for version (custom/beta?) of portable python that is python 3.x and includes pygame. I know pygame hasn't been fully converted to 3.x yet, but for what I need it for it works perfectly.
Install Pygame, then take your entire Python folder and put it where you want it to go.
If you mean you want to be able to use python (filename).py on the terminal, then you will have to change the PATH variable in the terminal, or add the shebang line #!usr\bin\python onto your programs.
Maybe I have not fully understood what you're after. Still, let me try to answer:
The release of Python 3.3 now includes VirtualEnv in the standard library, now called venv.
So in a command line you can type
/path/to/python3.3/bin/pyvenv /path/to/new/virtual/environment
To create a folder with links to your python 3.3 installation. That new folder makes it easy to install any PyPi packages into, for example:
cd /path/to/new/virtual/environment
./bin/pip install adventure
to install Adventure.
You then probably want to follow PyGames documentation to install the Py3 branch
Then, like user beary605 already answered you can bundle up your whole virtual environment of python by tar'ing, rsync'ing or whatever means of distribution you envision.
There's also an older question covering Python 3 and Pygame compatibility on Mac OS.
To my knowledge there is nothing like what you are looking for available, however with a little DIY you might be able to alter a version of Portable Python (it's not updated anymore, but there's a version for Python 3). By saying this I am presuming you want to operate this from a flash drive. Depending on what Windows you are running the steps might be a bit different, but I'm guessing they would be similar to the steps in this thread: pygame not working with portable python

Proper Unix (.profile, .bash_profile) changes for Python usage

I new to Python and to programming in general. I'm a novice, and do not work in programming, just trying to teach myself how to program as a hobby. Prior to Python, I worked with Ruby for a bit and I learned that one of the biggest challenges was actually properly setting up my computer.
Background: I'm on a Macbook with OSX 10.7.
With Ruby, you have to (or rather, you should), edit your ./profile and add PATH info. When you install and use RVM, there are additional items you need to add to your bash_profile.
Do you have to make similar changes with Python? What are the best practices as I'm installing/getting started to ensure I can install modules and packages correctly?
python works out of the box on OS X (as does ruby, for that matter). The only changes I would recommend for a beginner are:
1) Python likes to be reassured that the terminal can handle UTF-8 before it will print Unicode strings. Add export LANG=en_US.UTF-8 to .profile. (It may be that the .UTF-8 part is already present by default on Lion - I haven't checked since Snow Leopard.) Of course, this is something that will help you in debugging, but you shouldn't rely on it being set this way on other machines.
2) Install pip by doing easy_install pip (add sudo if necessary). After that, install Python packages using pip install; this way, you can easily remove them using pip uninstall.
Take a loot at Python on the Macintosh page first. Like it says, Python comes pre-installed on Mac OS X. It means that you don't have to do anything special in order to use it.
To get started, you can run a Terminal.app, type python and that will get you Python interactive shell up and running.
However, Python on OS X might be of a slightly older version. For example, OS X 10.7.3 comes with Python 2.7.1, whereas latest release version of the Python is 3.2.3. If you want to use other versions, then you will have to install them. Then it all depends on what, where and how you install. If you want to have multiple versions alongside, you may need to set some environment variables like PATH to have binaries you installed found by the bash etc. You can do it through bash ~/.profile if needed.
But until you get to that point - don't worry about it use a version shipped with OS X. Once you want a newer one - download and install it. Then, if it doesn't work out of the box or you have any other problems or concerns, feel free to ask a more specific question.

How to maintain long-lived python projects w.r.t. dependencies and python versions?

short version: how can I get rid of the multiple-versions-of-python nightmare ?
long version: over the years, I've used several versions of python, and what is worse, several extensions to python (e.g. pygame, pylab, wxPython...). Each time it was on a different setup, with different OSes, sometimes different architectures (like my old PowerPC mac).
Nowadays I'm using a mac (OSX 10.6 on x86-64) and it's a dependency nightmare each time I want to revive script older than a few months. Python itself already comes in three different flavours in /usr/bin (2.5, 2.6, 3.1), but I had to install 2.4 from macports for pygame, something else (cannot remember what) forced me to install all three others from macports as well, so at the end of the day I'm the happy owner of seven (!) instances of python on my system.
But that's not the problem, the problem is, none of them has the right (i.e. same set of) libraries installed, some of them are 32bits, some 64bits, and now I'm pretty much lost.
For example right now I'm trying to run a three-year-old script (not written by me) which used to use matplotlib/numpy to draw a real-time plot within a rectangle of a wxwidgets window. But I'm failing miserably: py26-wxpython from macports won't install, stock python has wxwidgets included but also has some conflict between 32 bits and 64 bits, and it doesn't have numpy... what a mess !
Obviously, I'm doing things the wrong way. How do you usally cope with all that chaos ?
I solve this using virtualenv. I sympathise with wanting to avoid further layers of nightmare abstraction, but virtualenv is actually amazingly clean and simple to use. You literally do this (command line, Linux):
virtualenv my_env
This creates a new python binary and library location, and symlinks to your existing system libraries by default. Then, to switch paths to use the new environment, you do this:
source my_env/bin/activate
That's it. Now if you install modules (e.g. with easy_install), they get installed to the lib directory of the my_env directory. They don't interfere with existing libraries, you don't get weird conflicts, stuff doesn't stop working in your old environment. They're completely isolated.
To exit the environment, just do
deactivate
If you decide you made a mistake with an installation, or you don't want that environment anymore, just delete the directory:
rm -rf my_env
And you're done. It's really that simple.
virtualenv is great. ;)
Some tips:
on Mac OS X, use only the python installation in /Library/Frameworks/Python.framework.
whenever you use numpy/scipy/matplotlib, install the enthought python distribution
use virtualenv and virtualenvwrapper to keep those "system" installations pristine; ideally use one virtual environment per project, so each project's dependencies are fulfilled. And, yes, that means potentially a lot of code will be replicated in the various virtual envs.
That seems like a bigger mess indeed, but at least things work that way. Basically, if one of the projects works in a virtualenv, it will keep working no matter what upgrades you perform, since you never change the "system" installs.
Take a look at virtualenv.
What I usually do is trying to (progressively) keep up with the Python versions as they come along (and once all of the external dependencies have correct versions available).
Most of the time the Python code itself can be transferred as-is with only minor needed modifications.
My biggest Python project # work (15.000+ LOC) is now on Python 2.6 a few months (upgrading everything from Python 2.5 did take most of a day due to installing / checking 10+ dependencies...)
In general I think this is the best strategy with most of the interdependent components in the free software stack (think the dependencies in the linux software repositories): keep your versions (semi)-current (or at least: progressing at the same pace).
install the python versions you need, better if from sources
when you write a script, include the full python version into it (such as #!/usr/local/bin/python2.6)
I can't see what could go wrong.
If something does, it's probably macports fault anyway, not yours (one of the reasons I don't use macports anymore).
I know I'm probably missing something and this will get downvoted, but please leave at least a little comment in that case, thanks :)
I use the MacPorts version for everything, but as you note a lot of the default versions are bizarrely old. For example vim omnicomplete in Snow Leopard has python25 as a dependency. A lot of python related ports have old dependencies but you can usually flag the newer version at build time, for example port install vim +python26 instead of port install vim +python. Do a dry run before installing anything to see if you are pulling, for example, the whole of python24 when it isn't necessary. Check portfiles often because the naming convention as Darwin ports was getting off the ground left something to be desired. In practice I just leave everything in the default /opt... folders of MacPorts, including a copy of the entire framework with duplicates of PyObjC, etc., and just stick with one version at a time, retaining the option to return to the system default if things break unexpectedly. Which is all perhaps a bit too much work to avoid using virtualenv, which I've been meaning to get around to using.
I've had good luck using Buildout. You set up a list of which eggs and which versions you want. Buildout then downloads and installs private versions of each for you. It makes a private "python" binary with all the eggs already installed. A local "nosetests" makes things easy to debug. You can extend the build with your own functions.
On the down side, Buildout can be quite mysterious. Do "buildout -vvvv" for a while to see exactly what it's doing and why.
http://www.buildout.org/docs/tutorial.html
At least under Linux, multiple pythons can co-exist fairly happily. I use Python 2.6 on a CentOS system that needs Python 2.4 to be the default for various system things. I simply compiled and installed python 2.6 into a separate directory tree (and added the appropriate bin directory to my path) which was fairly painless. It's then invoked by typing "python2.6".
Once you have separate pythons up and running, installing libraries for a specific version is straightforward. If you invoke the setup.py script with the python you want, it will be installed in directories appropriate to that python, and scripts will be installed in the same directory as the python executable itself and will automagically use the correct python when invoked.
I also try to avoid using too many libraries. When I only need one or two functions from a library (eg scipy), I'll often see if I can just copy them to my own project.

Curious about python installation paths, especially on OSX

First: I'm running Macports. No problems with that, except:
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin
which is the value of sys.exec_prefix, for my macports python even though:
/opt/local/lib/python2.6/site-packages/
seems to be quite a logical place to put things, /opt/local being the macports --prefix, as it were. Why does easy_install put things in this odd Frameworks/Python.framework thing?
More importantly, can i use the methods here, to ensure that all my systemwide python, particularly the scripts which I really want in /opt/local/bin, things I use all over the place like (i|b)python for example are accessible?
So first I'd make the observation that the directory
/Library/Frameworks/Python.framework/Versions/2.6/...
is where you can find the OS X provided version of Python so I'd guess that what the MacPorts developers want to do is replicate the OS X Python directory structure but keep it as far away from the OS X version of Python as possible. Also I think replicating the structure allows you to install third-party extensions outside of the MacPorts modules. I've done that before so I know it's possible, its just you still need to make sure:
When installing the modules, the version that the installer encounters when doing a PATH search is the Python installation you want to install it to (ie. a module meant for MacPorts Python doesn't end up in OS X Python). The page you cited earlier spells out the procedure an installer goes through when trying to find a Python installation to install to so you have some hints there about what to look into if you have problems installing third party modules.
Once you have installed your modules you'll have to keep track of them yourself because MacPorts won't do that for you. On the bright side everything should be in the site-extensions folder of the Python installation, I think.
This question from the MacPorts FAQ kind of lays the groundwork for their philosophy of directory organization I think. Also this question too.

Categories