I've installed python 2x and 3x with Homebrew at /usr/local/Cellar/, and again with pydev at ~/.pyenv for both versions. Also installed with .dmg for both. I can't decide which is nicer to work on. Please advice me.
And I'd like to remove some. Which of these would be unnecessary and can be removed?
don't delete files on /usr/bin, if you want to remove some python, like python2: brew uninstall python2.
The pyenv is a very good tool. I'm use it betw on py2 or py3 very well.
And there is another good tool for python dev:virtualenv
Related
Using Ubuntu 16.04.
I was doing development in Python2.7, although recently moved to Python3.5, both of which come by default. The problem is, I find all the python libraries have to be reinstalled or downloaded for the next Python3. Also, the behaviour of Python seems weird because to execute the same script in python3, I have to enter in terminal
python3 script.py
which is different from other applications where I do not have to give the version number. Anyway, the questions I am trying to find answers are
To what extent are the libraries, packages (such as pip etc.) shared between 2.7 and 3.5? Or do I need double installations (and double the space) for everything now? A bit space limited in my old laptop.
Most of the installation instructions and commands I find online do not specify whether they are for 2 or 3. Given that I have two versions, how do I control/make sure they go to 3.5?
Is it advisable and possible to completely remove everything related to 2.7? Can I keep working with 3.5?
The first thing you need to know is that all official libraries and python tools for python3 got the "3" character to separate them from the previous versions. So, you need to use pip3, and not pip, python3, not python, and the packages are called python-pygame, not python-pygame.
So, to answer to you in order:
Yes, the you have to double the space needed if you decide to use both python2 and python3
Usually, if in the tool name there is 3, it is for python3, and if not it's for python2
Python2 and python3 are completly indipendent (different path, indipendent versions, etc.) so having python 2.7 installed doesn't affect python3 BUT since python 3 is the next version of python 2, it makes it obsolete (in my opinion) so if you don't have enough space for both, keeping python2 is absolutely not needed nor useful
If you want to control your python execution then you have various method or techniques:
For downloading packages according to version
You can use pip{version-name} to download the libraries. Like if you want to download library of python 2.7 then write
pip2.7 install package-name
for python 3.5 then use
pip3.5 install package-name
For execution of program:
If you want to execute the program accoridng to you choice of version then just use
python{version-name} script.py
eg:
python2 script.py
python3 script.py
or you just write down the path of your python version on the top of script. Please refer this for more details:
Why do people write #!/usr/bin/env python on the first line of a Python script?
I want to completely reinstall Python 2 but none of the guides I have found allow me to uninstall it. No matter what I do, python --version still returns 2.7.10, even after I run the Python 2.7.11 installer. All the other guides on StackOverflow tell me to remove a bunch of files, but python is still there.
This may be a bit late, but for future searchers I'll post anyway:
I was looking to do the same. But I came across this paragraph at the Foundation (Getting and uninstalling MacPython) which convinced me to leave well alone and not uninstall it.
The Apple-provided build of Python is installed in /System/Library/Frameworks/Python.framework and /usr/bin/python, respectively. You should never modify or delete these, as they are Apple-controlled and are used by Apple- or third-party software. Remember that if you choose to install a newer Python version from python.org, you will have two different but functional Python installations on your computer, so it will be important that your paths and usages are consistent with what you want to do.
Set your an alias to use the python version that you want to use from inside your .bashrc (or zsh if you use it).
Like:
alias python='/usr/bin/python3.4'
Agree with the accepted answer that uninstalling is a bad idea, but for those of you using HomeBrew to install your own Python, you don't need an alias as in #Mat Marsiglio's answer. Rather you can do what the HomeBrew installation suggestions:
export PATH="/usr/local/opt/python/libexec/bin:$PATH"
This gives brew's python precedence over the built-in one at /usr/bin/python
I am using pip to pull down libraries but didnt realize the key one is only for 2.7. So now I am working in the 2.7 directory but pip is still installing libs in 3.3. So pyCharm keeps saying the lib is missing.
I have the PATH var set (this is gasp fn windows 8) so that Python 2.7 comes first but i think the python exe isn't looking in the first place I had pip install things. Maybe there is a setting in pip that will install it elsewhere now?
Any hints on how to make this work would be great. Maybe I just need to start over w/o python 3.3?
Thank you for your time!
Try these two solutions:
1)Remove python3.3 from the path variable and try installing library using pip now. so that pip from python27 can install things.
2)if this doesn't work then use
C:\python27\Scripts\pip.exe install
Oh My Crap, this is so easy. Thank you to AMWinter for this:
http://www.virtualenv.org/en/latest/virtualenv.html
It seems to manage all this chaos of the Python version (and library versions) for me easy. Of course I needed to tell it the python version (with flag -p) but that was it.
(although it did not put pip where it said it would - just pls note)
Dirk and Bakuriu are appreciated as well. Like Ruby, I realize managing versioning is a necessary evil.
Thank you all!
If I install several packages with Python 2.6 (e.g. using easy_install) and then I want to upgrade to Python 2.7, is there a way to upgrade Python and then automatically "import" all those installed packages along with it? Or do they have to be reinstalled?
Two related questions: (1) if a package is installed in a Python 2.6 packages directory, is it legitimate to import it into the PYTHONPATH of a newer Python, like Python 2.7, or must all the packages be reinstalled with Python 2.7? (2) if I use easy_install, how can I tell it to use the newer Python? E.g. 2.7 instead of 2.6? Or should I just reinstall easy_install using Python 2.7 to do this? thanks.
First, this is one of the many reasons you want to use pip instead of easy_install. (You still need easy_install to get pip itself, but beyond that, don't touch it ever again.) If you'd used pip, you could just do this:
pip freeze > modules.dump
That gives you a list of all of the modules you have installed, and their version numbers. Most of the time, you can just take the list of modules (line.split('==')[0] for line in f) and pass it to pip install.
But that's for future reference. For today, you have to piece it together yourself by looking through your site-packages directory. Fortunately, many things will end up as foo_bar-1.2.3.4-blah-blah.egg, so all you have to do is guess whether the package is named foo-bar or foo_bar at PyPI, and usually even if you guess wrong, easy_install or pip will get the right thing anyway. So, you can't quite automate it, but you can get close.
But yes, however you do it, you do need to reinstall. Anything that requires C extension code has to be recompiled. Pure-Python packages may not need to be changed, but they may, and you're better safe than sorry. Also, if you try to copy some things over but not others, you're going to make a big mess of your dependencies.
(1) if a package is installed in a Python 2.6 packages directory, is it legitimate to import it into the PYTHONPATH of a newer Python, like Python 2.7, or must all the packages be reinstalled with Python 2.7?
Don't do that; reinstall them, as explained above.
(2) if I use easy_install, how can I tell it to use the newer Python? E.g. 2.7 instead of 2.6? Or should I just reinstall easy_install using Python 2.7 to do this? thanks.
You need the 2.7 easy_install. You can usually use a 2.7 easy_install with 2.6 by running, e.g., python2.6 $(which easy_install), but the other way around isn't guaranteed to work.
And you don't want to do that anyway. If you want two versions of Python in parallel, you want two versions of easy_install—normally you want to end up with easy_install-2.6 and easy_install-2.7, with easy_install as a symlink to whichever one you consider your "primary" python.
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.