How do I install packages/modules for Python 3.6? - python

I'm super new to Python, and can't figure out how to install packages or modules. I know you can use Pip to easily install them, but none of the commands I've found have done anything but give me errors. Any help would be appreciated.

Have you tried pip install? A good thing to remember is pip usually requires sudo on linux distributions. Also, for some modules it's easier to use conda, since it takes care of dependencies. It this is the best general information I can give. If you told me some packages you've tried to install, that would help a lot!

Related

Installing numpy/matplotlib/etc. on Mac

I am very new to python, and am having difficulty getting any packages from online to install properly. I'm pretty sure I'm doing something fundamentally wrong, but since I am new to language I am unsure of what it is. I have read through several online sources but still can't get it to work. I feel really dumb asking this, but I would greatly appreciate it if someone could walk me through how to install it starting from the point of downloading the package online. Thanks!
If your primary use case is the scipy stack, for example as a Matlab replacement. I would highly recommend using the Anaconda distribution. It is brilliant for new comers, a large majority of what you are likely after comes pre installed.
Download it here:
https://www.continuum.io/downloads#_macosx
I would recommend picking the python 3 64bit installer. A direct link to the download is here:
https://3230d63b5fc54e62148e-c95ac804525aac4b6dba79b00b39d1d3.ssl.cf1.rackcdn.com/Anaconda3-2.3.0-MacOSX-x86_64.pkg
Your best bet is to use Homebrew as your general package manager and then use use it to install Pip to manage all of your python packages. Both of the links below will walk you through how to do these things.
See Homebrew link
See How to install pip on Mac for Pip
Go here and download get-pip.py
Then, from terminal run the command python get-pip.py
This should install pip for you. Pip is awesome, and you really want to have it. Now, all you have to do is run this command from terminal:
pip install matplotlib
Or to get Numpy:
pip install numpy

Installing Pillow on FreeBSD based shell hosting

I'm struggling with Pillow on my shell hosting based on FreeBSD.
Running pip install Pillow (inside virtualenv, if it does matter) results with this:
http://justpaste.it/ich2
I have absolutely no idea what's wrong. Someone knows the problem?
Ok, running installer with MAX_CONCURRENCY=1 pip install pillow did the trick.
Maybe it will be useful for someone.
Suggested way is to install from packages; they often contain patches that fix various system-specific problems. Doing "pkg search pillow" shows that you can do "pkg install py27-pillow".

Why isn't pip updating my numpy and scipy?

My problem is that pip won't update my Python Packages, even though there are no errors.
It is similar to this one, but I am still now sure what to do. Basically, ALL my packages for python appear to be ridiculously outdated, even after updating everything via pip. Here are the details:
I am using pip, version 1.5.6.
I am using Python, version 2.7.5
I am on a Mac OSX, verion 10.9.5.
Using that, I have:
My numpy version is 1.6.2.
My scipy version is 0.11.0.
My matplotlib version is 1.1.1.
Even after I try:
sudo pip uninstall numpy
Followed by:
sudo pip install numpy
They both complete successfully, but when I go into python and check the version of numpy, it is still the old one. (As are all the other packages).
Not sure what is going on here?... How can this be fixed? P.S. I am new to this, so I might need explicit instructions. Thanks. Also, if anyone wants, I can provide a screenshot of pip as it is installing numpy.
EDIT:
Commands I ran as per the comments:
$which -a pip
/usr/local/bin/pip
$ head -1 $(which pip)
#!/usr/bin/python
$ which -a python
/usr/bin/python
In OS X 10.9, Apple's Python comes with a bunch of pre-installed extra packages, in a directory named /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python. Including numpy.
And the way they're installed (as if by using easy_install with an ancient pre-0.7 version of setuptools, but not into either of the normal easy_install destinations), pip doesn't know anything about them.
So, what happens is that sudo pip install numpy installs a separate copy of numpy into '/Library/Python/2.7/site-packages'—but in your sys.path, the Extras directory comes before the site-packages directory, so import numpy still finds Apple's copy. I'm not sure why that is, but it's probably not something you want to monkey with.
So, how do you fix this?
The two best solutions are:
Use virtualenv, and install your numpy and friends into a virtual environment, instead of system-wide. This has the downside that you have to learn how to use virtualenv—but that's definitely worth doing at some point, and if you have the time to learn it now, go for it.
Upgrade to Python 3.x, either from a python.org installer or via Homebrew. Python 3.4 or later comes with pip, and doesn't come with any pip-unfriendly pre-installed packages. And, unlike installing a separate 2.7, it doesn't interfere with Apple's Python at all; python3 and python, pip3 and pip, etc., will all be separate programs, and you don't have to learn anything about how PATH works or any of that. This has the downside that you have to learn Python 3.x, which has some major changes, so again, a bit of a learning curve, but again, definitely worth doing at some point.
Assuming neither of those is possible, I think the simplest option is to use easy_install instead of pip, for the packages you want to install newer versions of any of Apple's "extras". You can get a full list of those by looking at what's in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python. When you upgrade numpy, you probably also want to upgrade scipy and matplotlib; I think everything else there is unrelated. (You can of course upgrade PyObjC or dateutil or anything else you care about there, but you don't have to.)
This isn't an ideal solution; there are a lot of reasons easy_install is inferior to pip (e.g., not having an uninstaller, so you're going to have to remember where that /Library/blah/blah path is (or find it again by printout out sys.path from inside Python). I wouldn't normally suggest easy_install for anything except readline and pip itself (and then only with Apple's Python). But in this case, I think it's simpler than the other alternatives.
Old question, but I found it when trying to solve this issue, will post my solution.
I found #abarnert's diagnosis to be correct and helpful, but I don't like any of the solutions: I really want to upgrade the default version of numpy. The challenge is that the directory these guys are in (which #abarnert mentioned) cannot be touched even by sudo, as they are in this "wheel" group. In fact, if you go there and do sudo rm -rf blah, it will give you a permission denied error.
To get around this, we have to take drastic action:
Reboot the computer in recovery mode
Find the terminal and type csrutil disable
Reboot normally, then upgrade numpy with pip2 install --user --upgrade numpy (and same for any other packages that have this problem)
Repeat steps a and b, this time changing "disable" to "enable"
Note: "csrutil disable" is serious business that can destabilize your machine, I would use it only when absolutely necessary and re-enable it ASAP. But AFAIK it's the only way to upgrade Python packages in a wheel directory.
Rename the numpy and scipy versions installed by Apple in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/ so it starts using the newer versions installed by Pip.

Python import matplotlib.pyplot not working

I have tried easy_install matplotlib and have the following:
matplotlib-1.2.0-py2.7-macosx-10.7-intel.egg
installed in my Library/Python/2.7/site-packages.
When I move to a different folder to make use of contents in that folder and try to
"import matplotlib.pyplot" it says : ImportError: No module named matplotlib.pyplot
This makes me think that the easy_install has been done incorrectly. This question is quite basic but I am working with mac osx and other than learn that it is incredibly hard to install this module on osx I have learnt little else from most sources so I would like to know if anyone on SO can help me with my problem. I am a python novice and would really appreciate the help.
As a general rule, you should always use pip instead of easy_install, except for a handful of libraries (all of which document that fact, and the only ones you're likely to care about are readline, and of course pip itself).
If you're on OS X 10.7 or 10.8, using the Apple-installed Python, you have easy_install built-in, but not pip. To fix that:
sudo easy_install pip
And now, you can do this:
sudo pip install matplotlib
Normally, this won't actually solve the kind of problem you're having. The reason to use pip is that easy_install has no uninstall functionality, it handles upgrades badly, it can end up leaving stuff part-way installed when it fails, it doesn't work right with virtualenv, etc.
But it sounds like you got lucky, and this change magically fixed your problem. We could try to diagnose the original problem. (Why were you using -m with easy_install? Does pip install --egg work? And so on.) But I'm guessing you're happy with the result and just want to leave well-enough alone.
For future readers who come along, it seems like sudo easy_install -m matplotlib on the stock Apple 10.7 Python 2.7 does not work, but sudo pip install matplotlib does, and that may be good enough for them as well.

Cleaning Python modules an have fresh start Mac OS X

I am not a total newbie but I am trying to install modules for quite a long time and at this point i would like to have a fresh start and install python and all the modules I need so i really understand them. My problem is that some of them import, but most of them install either to the wrong site-packages or dont import maybe because i messed up my system/python. Also I tried the PYTHONPATH and PATH to set this up right, but it never worked.
So my questions are:
Is there a way to ensure I can clean everything up and start from zero ?
Ideally this would be without having to set up Mac OSX new.
Is there a way to install all the modules in the correct place (whatever the directory is I dont care, it should just work)?
Is there a good step-by-step description on how installing modules works. And I dont mean just the info to use easy_install, pip install etc, but a way to fully understand what I need to consider, where I need to put them, why these modules are recognized in certain directories, how the system finds them and most important what are the most common pitfalls and how to avoid them.
I also tried Macports and various other similiar ways to install but even if some of them worked and while I am sure that these are really great tools, most I had to hack to work.
So if someone can recommend a good and stable way to install a lot of modules at once, this would be incredibly useful.
Thanks a lot !!!!
And sorry for the long questions.
Buildout and virtualenv should be what you are looking for.
Buildout helps you configure a python installation and virtualenv allows you to isolate multiple different configurations from each other.
Here's a nice blog post explaining how to use them together.
Also, see this other question: Buildout and Virtualenv
You can safely install an up-to-date Python 2 and/or Python 3 on OS X using the python.org installers here. They will coexist with any other Pythons you have installed or that were shipped by Apple with OS X. To install packages, for each Python instance first install Distribute which will install a version-specific easy_install command, i.e. easy_install-2.7 or easy_install-3.2. Many people prefer to use pip to manage packages; you can use easy_install to install a version-specific copy of it. If you want something fancier, you could also install virtualenv but, with the isolation provided by Python framework builds on OS X, that isn't as necessary as on most other platforms.
Is there a way to install all the modules in the correct place?
Download and untar/gunzip/etc the module source (Most of the modules ares available in gzip form at http://pypi.python.org/pypi), then run configure with --prefix set to the same thing for every install:
[ 11:06 jon#hozbox.com ~ ]$ ./configure --prefix=/usr/local
/usr/local is usually the default, but it doesn't hurt to specify it and will ensure that every module you install will be placed in /usr/local/lib/python/...
Is there a good step-by-step description on how installing modules works?
The Python website has a great page called: Installing Python Modules
http://pypi.python.org/pypi
http://docs.python.org/install/index.html

Categories

Resources