I am new to Python and there are some things which I am not able to apprehend. Questions may seem like very kiddish, so bear with me.
As you know, Ubuntu comes with an outdated Python version. I wished to use the latest python. But since it is recommended not to override the system's python, I installed virtualenv.
I installed pip first, using sudo apt-get install python-pip.
Then installed virtualenv, using sudo pip install virtualenv, and did all the configurations required to link it to the latest python.
The questions which I want to ask are-
Where does the command pip install <module> store the module in the system? I am asking this question because there is a section in this link, which says "Installation into Python". I was confused by this, thinking whether installing a python module is sensitive to which python version I am using. If it is so, then where does pip install the module if I am using virtualenv and otherwise.
I have manually installed Apache HTTP Server 2.4.23 using this link. While installing mod_wsgi using command sudo pip install mod_wsgi, I am getting this error
RuntimeError: The 'apxs' command appears not to be installed or is not
executable. Please check the list of prerequisites in the
documentation for this package and install any missing Apache httpd
server packages.
I searched for it and the solution is to install developer package of Apache. But the problem is that I am not able to find it anywhere on it's site. I want to install it manually. What to do? Also, If I install it through sudo apt-get install apache2-dev, Will there be any difference ?
Note: As mentioned on this link, I have already set the value of APXS environment variable to the location of apxs script, which is /usr/local/apache/bin/apxs.
Concerning 1., if I have well understood, you would like to have the last 2.7 or 3.5 Python version on your distribution. Actually, you can have multiple python distribution on your distribution. I would suggest you to have a look on conda/anaconda (https://www.continuum.io/downloads) : it is very powerful and i think it would better suit you than virtualenv: virtualenv would enable you to create a separate python environnement, but it would not install a newer version of Python.
Concerning 2, I am not an expert in Apache2, but I would have used apt-get instead of re-compiling apache. While compiling, you may need some dependancies to build the mod_wsgi module. So I think it is way more easy to use the pre-built packages from your ubuntu.
I have installed scipy and numpy, and they are being used with my current, desired version of python 2.7.6 (I am running on OSX Mavericks and had to upgrade.) However, when I pip installed matplotlib, by default it referenced my previous python version, 2.7.5, thus making it troublesome to use (obviously.)
How do I change which version of python matplotlib uses so I can import and use the library?
Thanks.
The way I would solve this problem is like this, firstly one would need to go into your 2.7.6 directory, and under the Scripts folder you will find the pip executable. My suggestion is (because its difficult to debug this kind of people without having all the details) is this:
./pip install matplotlib
And see if this succeeds, otherwise, I suggest using pyenv to manage your python installations.
I suggest you use Macports for installing additional Python versions on OS X. Once Macports is installed, it's fairly easy to install Python 2.7.6. All you'd have to do is:
sudo port install python27
Now, you should be able to get all the libraries you need just as easily, using, too, Macports.
sudo port install py27-numpy
sudo port install py27-scipy
sudo port install py27-matplotlib
Macports should solve all the dependencies and, of course, link the packages to their correct Python versions, avoiding you a lot of headaches.
For a step by step guide on how to set up a nice, functional Python environment, visit: http://jakevdp.github.io/blog/2013/02/02/setting-up-a-mac-for-python-development/
I'm aware that there are similar questions on SO. This one, for example: What's the proper way to install pip, virtualenv, and distribute for Python?
I'd like to install these modules as per my Learn Python the Hard Way tutorial: http://learnpythonthehardway.org/book/ex46.html
I managed (I think) to install pip by using sudo easy_install pip but when I then ran pydoc modules I could not see it. So I'm not even sure it's installed.
The answer above in question 4324558 is difficult for me to understand: what's a bootstrap, what's curl and why would I set up a virtual environment? Yes, as a learner I should try to pick up as much as I can but I don't want to first create the universe, I just want to get the task at hand done.
How do I install these modules? Is it as complicated as it sounds in the quoted answer? The top voted answer says "Install virtualenv into a bootstrap virtual environment. Use the that virtual environment to create more. Since virtualenv ships with pip and distribute, you get everything from one install."
I really don't get what all that means. Isn't there something about the "Zen" of python and a one true way to get things done? Or am I out of context here? What is "the right way" to install these modules?
I tried:
pip install virtualenv in the terminal and received the following output:
Wheel installs require setuptools >= 0.8 for dist-info support.
pip's wheel support requires setuptools >= 0.8 for dist-info support.
Storing debug log for failure in /Users/myname/.pip/pip.log
I'm using a Mac and python 2.7
To solve your issue,
Just install (or upgrade) the setuptools:
sudo easy_install -U setuptools
Then you can run again: pip install virtualenv
Try adding 'sudo' in your command as-
sudo pip install virtualenv
It worked for me.
Have a look at Python Development Environment on Mac OS X Mavericks 10.9.
I followed these steps as well when trying to get Python 2.7 and Python 3.3 installed on OS X. It doesn't tell you how to install nose and distribute, but you should have a working environment and you can pick up from there.
I did have a problem using virtualenv and pip with Python 3, the question and solutions is available here.
I am new to Python, trying to learn it by doing a tutorial based on "Dive into Python" book.
I am already in chapter about SOAP and I encountered some problems, when I tried to install all required libraries to use SOAP.
The tutorial says I need 3 libraries:
PyXML, fpconst, SOAPpy
I've installed fpconst succesfully.
However I can't install two others. I read on some forum that to install SOAPpy I need to have PyXML already installed, so maybe the problem is only in the first library.
I followed instructions in README, but I'm getting some error and I don't really know what is wrong and how can solve it. See screen for details. My version of Python is 2.7.2+ and I am trying to install PyXML version 0.8.4.
Full size
The errors states that such file or directory does not exist.
I am using Ubuntu 11.10.
PS: Ah! I forgot to mention that. I downloaded PyXML from this source :
http://sourceforge.net/projects/pyxml/
And it it written here that it is out of date and one shouldn't use it. So what is an alternative to PyXML?
If you are using Ubuntu, why not just install these with your package manager?
sudo apt-get install python-lxml python-fpconst python-soappy
The package manager should be your preferred way to install any software in a Linux distro - it will make your life a lot easier, and ensure you keep things up-to-date and can easily uninstall them.
Failing that, you could also use PyPi - the Python Package Index.
pip install lxml
pip install fpconst
pip install soappy
I'm starting to learn python and loving it. I work on a Mac mainly as well as Linux. I'm finding that on Linux (Ubuntu 9.04 mostly) when I install a python module using apt-get it works fine. I can import it with no trouble.
On the Mac, I'm used to using Macports to install all the Unixy stuff. However, I'm finding that most of the python modules I install with it are not being seen by python. I've spent some time playing around with PATH settings and using python_select . Nothing has really worked and at this point I'm not really understanding, instead I'm just poking around.
I get the impression that Macports isn't universally loved for managing python modules. I'd like to start fresh using a more "accepted" (if that's the right word) approach.
So, I was wondering, what is the method that Mac python developers use to manage their modules?
Bonus questions:
Do you use Apple's python, or some other version?
Do you compile everything from source or is there a package manger that works well (Fink?).
The most popular way to manage python packages (if you're not using your system package manager) is to use setuptools and easy_install. It is probably already installed on your system. Use it like this:
easy_install django
easy_install uses the Python Package Index which is an amazing resource for python developers. Have a look around to see what packages are available.
A better option is pip, which is gaining traction, as it attempts to fix a lot of the problems associated with easy_install. Pip uses the same package repository as easy_install, it just works better. Really the only time use need to use easy_install is for this command:
easy_install pip
After that, use:
pip install django
At some point you will probably want to learn a bit about virtualenv. If you do a lot of python development on projects with conflicting package requirements, virtualenv is a godsend. It will allow you to have completely different versions of various packages, and switch between them easily depending your needs.
Regarding which python to use, sticking with Apple's python will give you the least headaches, but If you need a newer version (Leopard is 2.5.1 I believe), I would go with the macports python 2.6.
Your question is already three years old and there are some details not covered in other answers:
Most people I know use HomeBrew or MacPorts, I prefer MacPorts because of its clean cut of what is a default Mac OS X environment and my development setup. Just move out your /opt folder and test your packages with a normal user Python environment
MacPorts is only portable within Mac, but with easy_install or pip you will learn how to setup your environment in any platform (Win/Mac/Linux/Bsd...). Furthermore it will always be more up to date and with more packages
I personally let MacPorts handle my Python modules to keep everything updated. Like any other high level package manager (ie: apt-get) it is much better for the heavy lifting of modules with lots of binary dependencies. There is no way I would build my Qt bindings (PySide) with easy_install or pip. Qt is huge and takes a lot to compile. As soon as you want a Python package that needs a library used by non Python programs, try to avoid easy_install or pip
At some point you will find that there are some packages missing within MacPorts. I do not believe that MacPorts will ever give you the whole CheeseShop. For example, recently I needed the Elixir module, but MacPorts only offers py25-elixir and py26-elixir, no py27 version. In cases like these you have:
pip-2.7 install --user elixir
( make sure you always type pip-(version) )
That will build an extra Python library in your home dir. Yes, Python will work with more than one library location: one controlled by MacPorts and a user local one for everything missing within MacPorts.
Now notice that I favor pip over easy_install. There is a good reason you should avoid setuptools and easy_install. Here is a good explanation and I try to keep away from them. One very useful feature of pip is giving you a list of all the modules (along their versions) that you installed with MacPorts, easy_install and pip itself:
pip-2.7 freeze
If you already started using easy_install, don't worry, pip can recognize everything done already by easy_install and even upgrade the packages installed with it.
If you are a developer keep an eye on virtualenv for controlling different setups and combinations of module versions. Other answers mention it already, what is not mentioned so far is the Tox module, a tool for testing that your package installs correctly with different Python versions.
Although I usually do not have version conflicts, I like to have virtualenv to set up a clean environment and get a clear view of my packages dependencies. That way I never forget any dependencies in my setup.py
If you go for MacPorts be aware that multiple versions of the same package are not selected anymore like the old Debian style with an extra python_select package (it is still there for compatibility). Now you have the select command to choose which Python version will be used (you can even select the Apple installed ones):
$ port select python
Available versions for python:
none
python25-apple
python26-apple
python27 (active)
python27-apple
python32
$ port select python python32
Add tox on top of it and your programs should be really portable
Please see Python OS X development environment. The best way is to use MacPorts. Download and install MacPorts, then install Python via MacPorts by typing the following commands in the Terminal:
sudo port install python26 python_select
sudo port select --set python python26
OR
sudo port install python30 python_select
sudo port select --set python python30
Use the first set of commands to install Python 2.6 and the second set to install Python 3.0. Then use:
sudo port install py26-packagename
OR
sudo port install py30-packagename
In the above commands, replace packagename with the name of the package, for example:
sudo port install py26-setuptools
These commands will automatically install the package (and its dependencies) for the given Python version.
For a full list of available packages for Python, type:
port list | grep py26-
OR
port list | grep py30-
Which command you use depends on which version of Python you chose to install.
I use MacPorts to install Python and any third-party modules tracked by MacPorts into /opt/local, and I install any manually installed modules (those not in the MacPorts repository) into /usr/local, and this has never caused any problems. I think you may be confused as to the use of certain MacPorts scripts and environment variables.
MacPorts python_select is used to select the "current" version of Python, but it has nothing to do with modules. This allows you to, e.g., install both Python 2.5 and Python 2.6 using MacPorts, and switch between installs.
The $PATH environment variables does not affect what Python modules are loaded. $PYTHONPATH is what you are looking for. $PYTHONPATH should point to directories containing Python modules you want to load. In my case, my $PYTHONPATH variable contains /usr/local/lib/python26/site-packages. If you use MacPorts' Python, it sets up the other proper directories for you, so you only need to add additional paths to $PYTHONPATH. But again, $PATH isn't used at all when Python searches for modules you have installed.
$PATH is used to find executables, so if you install MacPorts' Python, make sure /opt/local/bin is in your $PATH.
There's nothing wrong with using a MacPorts Python installation. If you are installing python modules from MacPorts but then not seeing them, that likely means you are not invoking the MacPorts python you installed to. In a terminal shell, you can use absolute paths to invoke the various Pythons that may be installed. For example:
$ /usr/bin/python2.5 # Apple-supplied 2.5 (Leopard)
$ /opt/local/bin/python2.5 # MacPorts 2.5
$ /opt/local/bin/python2.6 # MacPorts 2.6
$ /usr/local/bin/python2.6 # python.org (MacPython) 2.6
$ /usr/local/bin/python3.1 # python.org (MacPython) 3.1
To get the right python by default requires ensuring your shell $PATH is set properly to ensure that the right executable is found first. Another solution is to define shell aliases to the various pythons.
A python.org (MacPython) installation is fine, too, as others have suggested. easy_install can help but, again, because each Python instance may have its own easy_install command, make sure you are invoking the right easy_install.
If you use Python from MacPorts, it has it's own easy_install located at: /opt/local/bin/easy_install-2.6 (for py26, that is). It's not the same one as simply calling easy_install directly, even if you used python_select to change your default python command.
Have you looked into easy_install at all? It won't synchronize your macports or anything like that, but it will automatically download the latest package and all necessary dependencies, i.e.
easy_install nose
for the nose unit testing package, or
easy_install trac
for the trac bug tracker.
There's a bit more information on their EasyInstall page too.
For MacPython installations, I found an effective solution to fixing the problem with setuptools (easy_install) in this blog post:
http://droidism.com/getting-running-with-django-and-macpython-26-on-leopard
One handy tip includes finding out which version of python is active in the terminal:
which python
When you install modules with MacPorts, it does not go into Apple's version of Python. Instead those modules are installed onto the MacPorts version of Python selected.
You can change which version of Python is used by default using a mac port called python_select. instructions here.
Also, there's easy_install. Which will use python to install python modules.
You may already have pip3 pre-installed, so just try it!
Regarding which python version to use, Mac OS usually ships an old version of python. It's a good idea to upgrade to a newer version. You can download a .dmg from http://www.python.org/download/ . If you do that, remember to update the path. You can find the exact commands here http://farmdev.com/thoughts/66/python-3-0-on-mac-os-x-alongside-2-6-2-5-etc-/
I use easy_install with Apple's Python, and it works like a charm.
Directly install one of the fink packages (Django 1.6 as of 2013-Nov)
fink install django-py27
fink install django-py33
Or create yourself a virtualenv:
fink install virtualenv-py27
virtualenv django-env
source django-env/bin/activate
pip install django
deactivate # when you are done
Or use fink django plus any other pip installed packages in a virtualenv
fink install django-py27
fink install virtualenv-py27
virtualenv django-env --system-site-packages
source django-env/bin/activate
# django already installed
pip install django-analytical # or anything else you might want
deactivate # back to your normally scheduled programming