Installing rpy or rpy2 on mac - python

I'm in the process of trying to install rpy or rpy2 on my Macbook so I can use R from python. Information about rpy can be found here: http://rpy.sourceforge.net/index.html
My problem is in the installation itself. I can't seem to make python recognize Rpy using import command: I keep getting the message "No module named rpy2". Does anyone know where I can find some step-by-step instructions on how to successfully install this? I have already installed both python and R, and both are working perfectly. Thanks in advance!

Try easy_install rpy2. You need to install easy_install before that.
I took that from here

I long gave up on these issues on my Mac. Since I installed OS Lion, I found that I needed to switch to MacPorts and then installing packages like RPy2 from their repository.
I know some people like to dig into the system and learn all the idiosyncrasies of the architecture and keep a vanilla install of python on their Mac. I find that i get problems like yours too frequently and they distract me from real work.
I just download the MacPorts modules when I need them and get on with the problem at hand. Others say the same thing about HomeBrew but I have only worked with MacPorts and it makes installation of modules too easy. You may want to invest some time investigating if either of these solutions work for you.
Another approach to using package managers like MacPorts or HomeBrew is to use a virtualenv and install python and all related modules there. Again, not a solution I have tried directly, but a quick search will show you many endorsements for this approach to using a specific Python executable and packaging its modules In an isolated environment.

as long as you have pip installed on your mac, then life will be easy as:
sudo pip install rpy2

If you want rpy it isn't on macport, at least a search of their packages only showed rpy2. According to the rpy web site its in fink. However at the moment fink is down so I can't verify this. Which is irritating because I need rpy (not rpy2) because another package has a dependency on it.
I also tried pip to find rpy and it said no package, which is a shame because pip is great for python installs (provided I remember to use 'sudo' first.

Related

Why Should Homebrew be used to Install Python?

I have been reading a lot of the tutorials around the web and answers on the site about using Homebrew. When it comes to Python though, the advice leaves me with more questions than answers.
I understand the how, but none of the answers I have seen so far have really explained the why behind using Homebrew to install Python and what the benefits are to installing Python with Homebrew as opposed to using OS-X installers provided by the Python Foundation?
The newest versions of the installers from Python and the current implementation of PIP seem to be working pretty well, so I would really appreciate any input on my question. I have worked with Python for a while but from more of a tactical, one off problem solving perspective and I am brand new to tools like Brew and version control software such as Git. I am trying to get up the learning curve. Finding an answer to why I would choose to go with a Homebrew install over just heading over to python.org and downloading from them and then using pip to install packages might help me to understand the benefits of a tool like Homebrew.
So I guess, what does Homebrew give me that going through the installation put in place by TPF does not?
Are there advantages/disadvantages to where Homebrew installs Python and Python packages over the /Library/Frameworks/ and the site-packages folder within that framework?
Though this last question is too broad and likely out of scope, if anyone would also address or provide a link to a good answer on what the benefits are of using Homebrew in general, I'd appreciate it?
Thank you,
The big advantage of using a package manager like Homebrew is it makes it easier to keep your Python installation up to date. If you download Python from the website, then to update it means you'll need to go back to the website and download a new copy of Python (or whatever it is that you need to update that could have been installed with Homebrew).
Also, when downloading installers, I find they tend to clutter up my downloads folder and require me to periodically clean up unused files. I'd rather spend my time coding instead of managing my disk space usage.
When it comes to updating any package with Homebrew, the command is simple:
brew upgrade
And this will update all outdated packages that you installed with Brew.
Now, this isn't something unique to Homebrew. Macports, PIP, npm, Maven, and other package management tools are also able to manage the versions of modules or tools you install.
For more information, see Safari Books Online - Keeping Your Homebrew Up To Date.
A few reasons not to use system python on OS X from this post,
Apple doesn’t always do a good job on keeping the Python runtime environment up to date,
it can be cumbersome to play with permissions just to install third-party Python libraries,
finally, Apple has a tendency to wipe-out your site-packages with every major OS upgrade.
The use of an independent package manager for Python modules, such as Homebrew, conda, Macports, ets. is thus preferred.

Is there a more efficient way to satisfy project dependencies than pip?

I work on a system and the hosting guys don't want to use an install script that uses pip. Now we have a large pip requirements file that install the dependencies. Is there any other way to do it than using pip? Can it be done using yum or apt-get ? We are using Linux.
For god's sake, please do not fall back to using the distribution's package manager just because your hosting guys do not understand what pip+virtualenv is good for.
Python packages in Linux distribution repositories are often outdated and may come with quirks that other Python package authors did not plan for. This is especially true for Python packages with compiled code. If a documentation tells you that a certain dependency should be obtained directly from PyPI via pip, then you better follow that requirement. Convince your hosting guys to use the right tools, namely pip combined with virtualenv. The latter will create an isolated environment and make sure that the system will stay clean (really, nobody needs to do a sudo pip install, which probably is the thing your hosting guys are afraid of).

Is it practical to have both Python 2.7 and 3.3 installed at the same time?

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!

Installing MatplotLib in mac osx lion

I was trying to install matplotlib in Mac OSX Lion. Tried to used the binary that is in the sourcefourge site, but I got this error: "matplotlib requires System Python 2.7 to install".
I went to the Terminal and typed python --version and its check the requirements.
After this I tried to used the pip, and while doing so é got the following error:
"src/_image.cpp:908: error: invalid use of incomplete type ‘struct png_info_def’"
Can you give me clues in how to install it?
Many thanks.
EDIT: I found a way, without having to install a new version of python:
http://the.taoofmac.com/space/blog/2011/07/24/2222
This is because of a change in the API for libpng v1.5 (which is included with Mac OSX Lion). The changes has already been pushed upstream, so you will need to compile from the upstream repository until the next release.
You can follow the instructions on http://jholewinski.wordpress.com/2011/07/21/installing-matplotlib-on-os-x-10-7-with-homebrew/
I followed this page's instructions. I got stuck at
pip install -e git+https://github.com/matplotlib/matplotlib#egg=matplotlib-dev
Then I did:
git clone https://github.com/matplotlib/matplotlib.git
cd matplotlib
python setup.py build
python setup.py install
Checked my installation by typing in terminal:
python
import matplotlib
print matplotlib.__version__
print matplotlib.__file__
I got version 0.10.0 dev (as of this writing) and path /usr/local/Cellar/...
You can try with an "official" python distribution, apple might have tweaked the supplied one. You can find the 2.7 here: http://www.python.org/download/
You might have to re-install numpy as well afterwords: http://sourceforge.net/projects/numpy/files/NumPy/1.6.1/
I would suggest to install scipy as well
Let me know if it works ;)
I would recommend using macports, it should take care of dependencies and would be indepedent of the system python version.
EDIT: Just a few clarifications, taking into account comments to this answer.
Why use macports (or another installer)? Because they take care of dependencies, provide functionality to uninstall and switch between versions (I've used the latter successfully for gcc and python). And because the default installation location is not the system executable location. Overriding the system python can break applications that rely on it (this is certainly true in many Linux distributions, maybe less so on mac OS X).
When is it particularly useful? When you want to install on top of a version of python that is different to system python, and when you have non-python extensions (C, C++, Fortran...).
What's the down side? As #Trond has mentioned in the comments, it is good if you're OK with default compilations of packages. You don't have a handle over configuration or compiler flags as you would if you built from source.
A good alternative to macports is fink, which seems to give you more control (build from source). I am not sure it is completely ready for mac OS X Lion yet.
I know it will take a lot more time, but I would reccomend installing python, numpy, and matplotlib from source to ensure that you have consistency in your system. From the error it could look like you have a problem with libPNG support. I have a written a "How to install python dev tools on Mac OSX" that you may find useful. It contains directions for how to install python, numpy, matplotlib and all necessary dependencies. I understand you are working with Python 2.7 and the directions I am listing is for Python 2.6.5, but it would be the same approach. Hope you get it to work.
You could just install the Python 2.6 version of Matplotlib, assuming that Python2.6 is included with Lion (py2.5 & 2.6 are included with Mac OS 10.6 "Snow Leopard" - try typing python2.6 to find out if that version is installed.).
On MacPorts you do this via something like:
sudo port install py26-matplotlib
where py26-... (or py25-..., py27-... etc.) indicates which python version it is meant for. (check the Pallet/ports list to get the correct package name, in case I guessed wrong)

Does Python have a package/module management system?

Does Python have a package/module management system, similar to how Ruby has rubygems where you can do gem install packagename?
On Installing Python Modules, I only see references to python setup.py install, but that requires you to find the package first.
Recent progress
March 2014: Good news! Python 3.4 ships with Pip. Pip has long been Python's de-facto standard package manager. You can install a package like this:
pip install httpie
Wahey! This is the best feature of any Python release. It makes the community's wealth of libraries accessible to everyone. Newbies are no longer excluded from using community libraries by the prohibitive difficulty of setup.
However, there remains a number of outstanding frustrations with the Python packaging experience. Cumulatively, they make Python very unwelcoming for newbies. Also, the long history of neglect (ie. not shipping with a package manager for 14 years from Python 2.0 to Python 3.3) did damage to the community. I describe both below.
Outstanding frustrations
It's important to understand that while experienced users are able to work around these frustrations, they are significant barriers to people new to Python. In fact, the difficulty and general user-unfriendliness is likely to deter many of them.
PyPI website is counter-helpful
Every language with a package manager has an official (or quasi-official) repository for the community to download and publish packages. Python has the Python Package Index, PyPI. https://pypi.python.org/pypi
Let's compare its pages with those of RubyGems and Npm (the Node package manager).
https://rubygems.org/gems/rails RubyGems page for the package rails
https://www.npmjs.org/package/express Npm page for the package express
https://pypi.python.org/pypi/simplejson/ PyPI page for the package simplejson
You'll see the RubyGems and Npm pages both begin with a one-line description of the package, then large friendly instructions how to install it.
Meanwhile, woe to any hapless Python user who naively browses to PyPI. On https://pypi.python.org/pypi/simplejson/ , they'll find no such helpful instructions. There is however, a large green 'Download' link. It's not unreasonable to follow it. Aha, they click! Their browser downloads a .tar.gz file. Many Windows users can't even open it, but if they persevere they may eventually extract it, then run setup.py and eventually with the help of Google setup.py install. Some will give up and reinvent the wheel..
Of course, all of this is wrong. The easiest way to install a package is with a Pip command. But PyPI didn't even mention Pip. Instead, it led them down an archaic and tedious path.
Error: Unable to find vcvarsall.bat
Numpy is one of Python's most popular libraries. Try to install it with Pip, you get this cryptic error message:
Error: Unable to find vcvarsall.bat
Trying to fix that is one of the most popular questions on Stack Overflow: "error: Unable to find vcvarsall.bat"
Few people succeed.
For comparison, in the same situation, Ruby prints this message, which explains what's going on and how to fix it:
Please update your PATH to include build tools or download the DevKit from http://rubyinstaller.org/downloads and follow the instructions at http://github.com/oneclick/rubyinstaller/wiki/Development-Kit
Publishing packages is hard
Ruby and Nodejs ship with full-featured package managers, Gem (since 2007) and Npm (since 2011), and have nurtured sharing communities centred around GitHub. Npm makes publishing packages as easy as installing them, it already has 64k packages. RubyGems lists 72k packages. The venerable Python package index lists only 41k.
History
Flying in the face of its "batteries included" motto, Python shipped without a package manager until 2014.
Until Pip, the de facto standard was a command easy_install. It was woefully inadequate. The was no command to uninstall packages.
Pip was a massive improvement. It had most the features of Ruby's Gem. Unfortunately, Pip was--until recently--ironically difficult to install. In fact, the problem remains a top Python question on Stack Overflow: "How do I install pip on Windows?"
And just to provide a contrast, there's also pip.
The Python Package Index (PyPI) seems to be standard:
To install a package:
pip install MyProject
To update a package
pip install --upgrade MyProject
To fix a version of a package pip install MyProject==1.0
You can install the package manager as follows:
curl -O http://python-distribute.org/distribute_setup.py
python distribute_setup.py
easy_install pip
References:
http://guide.python-distribute.org/
http://pypi.python.org/pypi/distribute
As a Ruby and Perl developer and learning-Python guy, I haven't found easy_install or pip to be the equivalent to RubyGems or CPAN.
I tend to keep my development systems running the latest versions of modules as the developers update them, and freeze my production systems at set versions. Both RubyGems and CPAN make it easy to find modules by listing what's available, then install and later update them individually or in bulk if desired.
easy_install and pip make it easy to install a module ONCE I located it via a browser search or learned about it by some other means, but they won't tell me what is available. I can explicitly name the module to be updated, but the apps won't tell me what has been updated nor will they update everything in bulk if I want.
So, the basic functionality is there in pip and easy_install but there are features missing that I'd like to see that would make them friendlier and easier to use and on par with CPAN and RubyGems.
There are at least two, easy_install and its successor pip.
As of at least late 2014, Continuum Analytics' Anaconda Python distribution with the conda package manager should be considered. It solves most of the serious issues people run into with Python in general (managing different Python versions, updating Python versions, package management, virtual environments, Windows/Mac compatibility) in one cohesive download.
It enables you to do pretty much everything you could want to with Python without having to change the system at all. My next preferred solution is pip + virtualenv, but you either have to install virtualenv into your system Python (and your system Python may not be the version you want), or build from source. Anaconda makes this whole process the click of a button, as well as adding a bunch of other features.
That'd be easy_install.
It's called setuptools. You run it with the "easy_install" command.
You can find the directory at http://pypi.python.org/
I don't see either MacPorts or Homebrew mentioned in other answers here, but since I do see them mentioned elsewhere on Stack Overflow for related questions, I'll add my own US$0.02 that many folks seem to consider MacPorts as not only a package manager for packages in general (as of today they list 16311 packages/ports, 2931 matching "python", albeit only for Macs), but also as a decent (maybe better) package manager for Python packages/modules:
Question
"...what is the method that Mac python developers use to manage their modules?"
Answers
"MacPorts is perfect for Python on the Mac."
"The best way is to use MacPorts."
"I prefer MacPorts..."
"With my MacPorts setup..."
"I use MacPorts to install ... third-party modules tracked by MacPorts"
SciPy
"Macs (unlike Linux) don’t come with a package manager, but there are a couple of popular package managers you can install.
Macports..."
I'm still debating on whether or not to use MacPorts myself, but at the moment I'm leaning in that direction.
On Windows install http://chocolatey.org/ then
choco install python
Open a new cmd-window with the updated PATH. Next, do
choco install pip
After that you can
pip install pyside
pip install ipython
...
Since no one has mentioned pipenv here, I would like to describe my views why everyone should use it for managing python packages.
As #ColonelPanic mentioned there are several issues with the Python Package Index and with pip and virtualenv also.
Pipenv solves most of the issues with pip and provides additional features also.
Pipenv features
Pipenv is intended to replace pip and virtualenv, which means pipenv will automatically create a separate virtual environment for every project thus avoiding conflicts between different python versions/package versions for different projects.
Enables truly deterministic builds, while easily specifying only what you want.
Generates and checks file hashes for locked dependencies.
Automatically install required Pythons, if pyenv is available.
Automatically finds your project home, recursively, by looking for a Pipfile.
Automatically generates a Pipfile, if one doesn’t exist.
Automatically creates a virtualenv in a standard location.
Automatically adds/removes packages to a Pipfile when they are un/installed.
Automatically loads .env files, if they exist.
If you have worked on python projects before, you would realize these features make managing packages way easier.
Other Commands
check checks for security vulnerabilities and asserts that PEP 508 requirements are being met by the current environment. (which I think is a great feature especially after this - Malicious packages on PyPi)
graph will show you a dependency graph, of your installed dependencies.
You can read more about it here - Pipenv.
Installation
You can find the installation documentation here
P.S.: If you liked working with the Python Package requests , you would be pleased to know that pipenv is by the same developer Kenneth Reitz
In 2019 poetry is the package and dependency manager you are looking for.
https://github.com/sdispater/poetry#why
It's modern, simple and reliable.
Poetry is what you're looking for. It takes care of dependency management, virtual environments, running.

Categories