Solved

How Do You Use MacPorts & Python To Create A Program?

Posted on 2016-07-27
22
139 Views
Last Modified: 2016-07-29
I have Yosemite and MacPorts installed along with Python on MacPorts.  I need to create a program with Python but it seems all the directions on the internet discuss using Python without MacPorts.  I had to use MacPorts because I couldn't get Python to load outside of MacPorts.  I posted that question yesterday and no one has offered to help so that's why I went the MacPorts route.
0
Comment
Question by:sharingsunshine
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 8
  • 4
22 Comments
 
LVL 30

Expert Comment

by:serialband
ID: 41731779
python exists on the Mac already.


I don't use Macports, so I don't know where it places its copy of python.  If it's placed in another directory, like Homebrew does, you'll have to change the path to include it.
0
 
LVL 40

Expert Comment

by:Eoin OSullivan
ID: 41731805
In terminal type
which python

Open in new window


This will tell you which instance of python on your mac is active

The version of python can be confirmed using
python --version

Open in new window


serialband is correct in that python is pre-installed on OSX and shouldn't need a custom installation

You only need to install manually if the version included in OSX doesn't meet your needs.

I saw your post about fixing a failed install but to be honest troubleshooting failed installs can be a real nightmare as there are 101 reasons for failure and there was nothing obvious in your post.  Maybe the pre-existing python install was the conflict .. then again maybe not.
0
 

Author Comment

by:sharingsunshine
ID: 41732212
You only need to install manually if the version included in OSX doesn't meet your needs.
I need a python to work so I can work of developing this script and modify it to my needs.

Open in new window


Maybe the pre-existing python install was the conflict .. then again maybe not.
Can someone just get me a working python that can work with this code:
http://www.tulane.edu/%7Ehoward/CompCultEN/webpages.html

Open in new window


I really don't care if I use MacPorts or not I just need a working python install so please advise me.

Thanks,
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

Author Comment

by:sharingsunshine
ID: 41732214
rjw which python
/opt/local/bin/python
rjw python --version
Python 2.7.12
0
 
LVL 30

Expert Comment

by:serialband
ID: 41732264
That looks like it's pointing to the MacPorts Python.  Mac's default Python should be in /usr/bin/python
0
 

Author Comment

by:sharingsunshine
ID: 41732930
OK then, how do I change it?
0
 
LVL 40

Expert Comment

by:Eoin OSullivan
ID: 41732955
I'm not sure precisely what your problem is .. you've Python installed .. its version 2.7 and it is working by all accounts .. you can run the "python" command in terminal - it doesn't matter that you've used the Homebrew version or the default version included with OSX

On the URL where are you having a problem?
http://www.tulane.edu/%7Ehoward/CompCultEN/webpages.html

Step 9.2.1?  Does it work now or what error are you getting?
0
 

Author Comment

by:sharingsunshine
ID: 41732963
rjw pip install BeautifulSoup4
Collecting BeautifulSoup4
  Using cached beautifulsoup4-4.5.0-py2-none-any.whl
Installing collected packages: BeautifulSoup4
Exception:
Traceback (most recent call last):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/commands/install.py", line 317, in run
    prefix=options.prefix_path,
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/req/req_set.py", line 742, in install
    **kwargs
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/req/req_install.py", line 831, in install
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/req/req_install.py", line 1032, in move_wheel_files
    isolated=self.isolated,
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/wheel.py", line 346, in move_wheel_files
    clobber(source, lib_dir, True)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/wheel.py", line 317, in clobber
    ensure_dir(destdir)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/utils/__init__.py", line 83, in ensure_dir
    os.makedirs(path)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 157, in makedirs
    mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/beautifulsoup4-4.5.0.dist-info'

Open in new window

0
 
LVL 40

Expert Comment

by:Eoin OSullivan
ID: 41732991
The clue is the last line ..
"OSError: [Errno 13] Permission denied:"

You can run into issues when you've multiple versions of python installed

This article covers the various bits
http://superuser.com/questions/915810/pip-not-working-on-hombrew-python-2-7-install

Basically you need to
1. Check that the homebrew base directory is on your $path variable ( this is normall done when installing Homebrew) but worth checking
In terminal enter
echo $PATH
If /usr/local/bin is not in your $PATH, put this line at the end of your ~/.profile file.
export PATH="/usr/local/bin:$Path"

2. Test that the Homebrew python install is fully complete
brew list python | grep pip
It should show you the homebrew python install

3. Run the command to check for any permissions after the install
brew postinstall python

Alternatively .. you could REMOVE the Homebrew python install from your mac and revert to using the OSX version as it should be perfectly OK
0
 

Author Comment

by:sharingsunshine
ID: 41733002
rjw echo $PATH
/Library/Frameworks/Python.framework/Versions/3.5/bin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/local/mysql/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Users/rjw/android-sdk-mac/tools:/usr/local/mysql/bin:/usr/local/mysql/bin
rjw brew list python | grep pip
-bash: brew: command not found

I don't have homebrew installed just MacPorts
0
 
LVL 40

Expert Comment

by:Eoin OSullivan
ID: 41733027
Sorry, I crossed my wires there on custom installs .. MacPorts and Homebrew are both in the same realm but operate a bit differently from each other.  Homebrew has surpassed MacPorts on OSX in terms of its features and functionality and I've stopped with macPorts a few years ago,

In terms of MacPorts install of Python I can see /opt/local/bin is already in the $PATH so you're covered there

The permission problem is a KNOWN problem with installing python packages using when you have a custom python installation from macports.

In short the command "pip install BeautifulSoup4" will NOT work when you're using python from Macports

If BeautifulSoup is a configured package for python you can look for it
port search beautifulsoup

It should find - https://www.macports.org/ports.php?by=library&substr=py27-beautifulsoup

Have you tried installing it using the following command to install BeautifulSoup via MacPorts?
sudo ports install py27-beautifulsoup

Open in new window

0
 

Author Comment

by:sharingsunshine
ID: 41733103
I got beautifulsoup and html5lib installed using the sudo port install command but the next command to import I am not clear how to accomplish it.

https://gyazo.com/c079090c5b0c0b1c1e08a02414357122 from looking at other documentation it looks that is the IDLE app but when I click on https://gyazo.com/17b4e2b9a4c01d43e4388570291e5619 IDLE.app nothing happens and no interpreter screen pops up.
0
 
LVL 40

Expert Comment

by:Eoin OSullivan
ID: 41733253
If you simply type "idle" as a command in terminal what happens?
0
 

Author Comment

by:sharingsunshine
ID: 41733261
rjw idle
Traceback (most recent call last):
  File "/opt/local/bin/idle", line 5, in <module>
    main()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/idlelib/PyShell.py", line 1553, in main
    root = Tk(className="Idle")
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 1815, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable
0
 
LVL 40

Expert Comment

by:Eoin OSullivan
ID: 41733274
You're missing another part
 sudo port install py27-tkinter

Open in new window

0
 

Author Comment

by:sharingsunshine
ID: 41733290
rjw sudo port install py27-tkinter
Password:
--->  Computing dependencies for py27-tkinter
--->  Cleaning py27-tkinter
--->  Scanning binaries for linking errors
--->  No broken files found.
rjw idle
Traceback (most recent call last):
  File "/opt/local/bin/idle", line 5, in <module>
    main()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/idlelib/PyShell.py", line 1553, in main
    root = Tk(className="Idle")
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 1815, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable
0
 
LVL 40

Accepted Solution

by:
Eoin OSullivan earned 500 total points
ID: 41733311
OK .. I googled the issue and it looks like IDLE on Macports needs X11

Can you check you've X11 installed
https://support.apple.com/en-us/HT201341
Here's the homepage
https://www.xquartz.org/

if it is installed then check you've the latest version
0
 
LVL 40

Expert Comment

by:Eoin OSullivan
ID: 41733332
After installing X11 .. if you still get an error .. try running the following command
 launchctl load -w /Library/LaunchAgents/org.macosforge.xquartz.startx.plist

Open in new window

0
 
LVL 30

Expert Comment

by:serialband
ID: 41733335
The cleanest way to switch the path back to the Mac default python, is to run:
sudo port uninstall python

However, you may have to start over with some of the pip installs in the default version.


"OSError: [Errno 13] Permission denied:"

The path errors are usually due to permissions.  MacPorts commands need to be run as root, so you should run it with sudo.  It's one of the reasons I moved on to Homebrew for personal users, since most Mac users don't share their system anywary.  Homebrew asks for root permissions to initially create the Homebrew install folders that are owned by an individual user.  If someone says to use brew, they're talking about Hombrew.  If someone says to use port, they're talking about MacPorts.  You can generally just swap the command name for the simple install, uninstall and status commands.

I started with Fink, then Macports, then Homebrew.  MacPorts and Fink work better if you want more centralized control on a shared computer system.  Homebrew is designed more to be accessed by a single user, although, if you understand unix permissions, you can make it work for multiple accounts too.

The cleanest way to switch the path back to the Mac default python, is to run:
sudo port uninstall python

That should remove the MacPorts versions of python and put the paths back to the original.

When you run Python scripts or environments like idle, those basic errors tell you that you're missing parts.  You can generally just cut and past your error lines into google and you'll find the answers pretty quickly to find what you're missing and you'd be able to add it faster than if you ask questions here.  

When you run Python scripts or environments like idle, those basic errors tell you that you're missing parts.  You can generally just cut and past your error lines into google and you'll find the answers pretty quickly to find what you're missing and you'd be able to add it faster than if you ask questions here and wait for an answer.

idle needs X11.  You can also run the python command without arguments and load your python files without installing X11.  idle has GUI features that help you align and view your source code with color coding easily.
0
 

Author Comment

by:sharingsunshine
ID: 41733369
I now have idle working so thanks to both of you.  Serialband einosullivan beat you on all of these answers.
0
 
LVL 30

Expert Comment

by:serialband
ID: 41734068
That's ok, I'm not here for points.
1
 

Author Comment

by:sharingsunshine
ID: 41734497
Serialband, I appreciate you letting me know and your putting others first.  I hope to interact with you again soon,
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We could spend the next millennium discussing the differences of the Mac and Windows platforms. The next century will continue to have fanatics on both side of the equation and neither side will win the war. However, that’s not why we are here. W…
Article by: Swadhin
Introduction of Lists in Python: There are six built-in types of sequences. Lists and tuples are the most common one. In this article we will see how to use Lists in python and how we can utilize it while doing our own program. In general we can al…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question