Python will not recognize installed MacPorts packages

Thank you in advance for your advice!

Background:

As for the people on this site, I am new to programming, and despite some research, I am not familiar with the use of Unix shells with which management packs are really associated or with anything that is done outside of the β€œDr. Java” IDE or The default GUI is R. I have a late 2008 macbook with OSX 10.5.8

My goal:

I am trying to install the following packages in Python: scipy, numpy, matplotlib, networkX

My story:

From what I understand, my 10.5.8 comes with Python 2.5, which the system needs to function, and you really shouldn't bother. The packages I installed require Python 2.7, so after reformatting my machine, I installed Python 2.7.2 for OSX 10.3 (the last Python / OSX that 2.7.X suggested) using .dmg from the Python site. Then I installed Xcode using .dmg (the appropriate version for my OS) from the Apple website and installed MacPorts (the corresponding version for my OS) using .dmg off of my site. Then I suggest that I used MacPorts to install packages:

sudo port install py27.numpy 

However, when I try to import the packages that I apparently installed, Python tells me that they do not exist. I am sure that I only have 2 versions of Python on my machine, 2.5 for OSX and 2.7.2 for me (how to check this?), And if I check which version of Python is running, whether through Shell or through IDLE I get :

 >>> import sys >>> print sys.version 2.7.2 (v2.7.2:8527427914a2, Jun 11 2011, 14:13:39) [GCC 4.0.1 (Apple Inc. build 5493)] 

If I run "what python" I get:

 /Library/Frameworks/Python.framework/Versions/2.7/bin/python 

When I check where MacPorts installed packages using

 port contents py27-packagename 

I get directories mainly in:

 /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ 

with multiple directories in

 /opt/local/share/py27-matplotlib/examples/ /opt/local/Library/Frameworks/Python.framework/Versions/2.7/share/doc/networkx-1.5/ 

and one directory in

 /opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/f2py /opt/local/share/doc/py27-matplotlib/CHANGELOG /opt/local/share/doc/py27-matplotlib/README.txt /opt/local/share/doc/py27-matplotlib/TODO 

My question is:

How do I get Python to recognize my packages? Ideally, I would like to configure it so that I can use Python IDLE and also call it from the command line.

I tried to replicate some of the solutions to: Find the MacPorts package? But I don’t really understand what I am doing so well, so it’s hard to adapt to what is being done there.

Thanks again everyone!

+3
source share
1 answer

I initially misunderstood your question to be standard - why can't I run my macports python? but in fact you indicated that you are trying to use self-imposed python, and you. the problem is that python does not know where to look for your libraries that are installed by macports.

You were on the right track with this question that you contacted. cm. , this answer , but change the path to your actual way your files macports libs, namely:

 export PYTHONPATH="/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages:$PYTHONPATH" 

see if this does the trick!

+2
source

Source: https://habr.com/ru/post/1497538/


All Articles