Using MacPorts to install modules via a certain pa

2019-08-01 02:21发布

问题:

I realize this is a very newbie question, but previous threads haven't been encouraging (see details below).

I've been using anaconda for most of my work via the IPython Notebook, python 2.7

However, there is a module which I could only properly download with MacPorts. Hence the current problem: when I try to use the Python command line in Terminal or use IPython notebooks, I will enter

import py-module

and I get

Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
ImportError: No module named py-module

So, obviously the $PATH is wrong. All my previous modules have been saved with conda to /anaconda/bin, but using sudo port install py-module is going to save in a different file, /opt/local.

Is it possible to set the path such that MacPorts will install a module into anaconda/bin such that I can import this module on ipython notebook via conda?

Previous threads have suggested simply choosing one or the other, i.e. removing anaconda entirely

rm -r ~/anaconda

and then just reinstalling all packages via MacPort. But I would prefer not to do this. Can't I re-direct the path such that

sudo port install py-module

installs the module into `/anaconda/bin/' ?

For previous takes, see

Getting PyGame to import in Python interpreter after MacPorts install

回答1:

While you could adjust your PYTHONPATH environment variable or modify the path using sys.path.insert, you should not try to mix a Python module built for MacPorts' Python with Anaconda. This may work just fine if the module is python-only, but as soon as the module contains compiled code it is not certain that the two installations are binary-compatible. In the best case, loading the module will fail if it isn't compatible, in the worst case, it will randomly crash.

So, yes, you should decide for one Python and just use that.