{"id":889,"date":"2010-09-17T15:39:11","date_gmt":"2010-09-17T23:39:11","guid":{"rendered":"http:\/\/owenmundy.com\/blog\/?p=889"},"modified":"2011-12-07T06:41:53","modified_gmt":"2011-12-07T14:41:53","slug":"how-to-install-scrapy-with-macports-full-version","status":"publish","type":"post","link":"https:\/\/owenmundy.com\/blog\/2010\/09\/how-to-install-scrapy-with-macports-full-version\/","title":{"rendered":"How to install Scrapy with MacPorts (full version)"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" title=\"macports-logo-top\" src=\"https:\/\/owenmundy.com\/blog\/wp-content\/uploads\/2010\/09\/macports-logo-top.png\" alt=\"macports-logo-top\" width=\"183\" height=\"70\" \/><strong> + <\/strong><img decoding=\"async\" style=\"vertical-align:22px\" title=\"logo\" src=\"https:\/\/owenmundy.com\/blog\/wp-content\/uploads\/2010\/09\/logo.png\" alt=\"logo\" width=\"184\" \/><\/p>\n<p>Here is a step-by-step explaining how I got <a href=\"http:\/\/scrapy.org\">Scrapy<\/a> running on my MacBook Pro 10.5 using <a href=\"http:\/\/www.macports.org\/install.php\">MacPorts<\/a> to install Python and all required libraries (libxml2, libxsit, etc.). The following has been tested on two separate machines with Scrapy .10.<\/p>\n<p>Many thanks to users <a href=\"http:\/\/stackoverflow.com\/questions\/2353957\/do-i-need-32bit-libxml2-for-python-on-snow-leopard\">here<\/a> who shared some helpful amendments to the <a href=\"http:\/\/doc.scrapy.org\/intro\/install.html\">default installation guide<\/a>. My original intention was to post this at stackoverflow, but their instructions discourage posting issues that have already been answered so here it is&#8230;<\/p>\n<p>1. Install <a href=\"http:\/\/developer.apple.com\/tools\/xcode\">Xcode<\/a> with options for command line development (a.k.a. &#8220;Unix Development&#8221;). This requires a <a href=\"http:\/\/developer.apple.com\/programs\/register\/\">free<\/a> registration.<\/p>\n<p>2. Install <a href=\"http:\/\/www.macports.org\/install.php\">MacPorts<\/a><\/p>\n<p>3. Confirm and update MacPorts<\/p>\n<p><code>$ sudo port -v selfupdate<\/code><\/p>\n<p>4. &#8220;Add the following to \/opt\/local\/etc\/macports\/variants.conf to prevent downloading the entire unix library with the next commands&#8221;<\/p>\n<p><code>+bash_completion +quartz +ssl +no_x11 +no_neon +no_tkinter +universal +libyaml -scientific<\/code><\/p>\n<p>5. Install Python<\/p>\n<p><code>$ sudo port install python26<\/code><\/p>\n<p>If for any reason you forgot to add the above exceptions, then cancel the install and do a &#8220;clean&#8221; to delete all the intermediary files MacPorts created. Then edit the variants.conf file (above) and install Python.<\/p>\n<p><code>$ sudo port clean python26<\/code><\/p>\n<p>6. Change the reference to the new Python installation<\/p>\n<p>If you type the following you will see a reference to the default installation of Python on MacOS 10.5 (Python2.5).<\/p>\n<p><code>$ which python<\/code><\/p>\n<p>You should see this<\/p>\n<p><code>\/usr\/bin\/python<\/code><\/p>\n<p><del datetime=\"2011-12-07T14:36:39+00:00\">To change this reference to the MacPorts installation, first install python_select<\/del><\/p>\n<p><del datetime=\"2011-12-07T14:36:39+00:00\"><code>$ sudo port install python_select<\/code><\/del><\/del><\/p>\n<p><del datetime=\"2011-12-07T14:36:39+00:00\">Then use python_select to change the $ python reference to the Python version installed above.<\/del><\/p>\n<p><del datetime=\"2011-12-07T14:36:39+00:00\"><code>$ sudo python_select python26<\/code><\/del><\/p>\n<p><strong>UPDATE 2011-12-07<\/strong>: python_select has been replaced by port select so&#8230;<\/p>\n<p>To see the possible pythons run<\/p>\n<p><code>port select --list python<\/code><\/p>\n<p>From that list choose the one you want and change to it e.g.<\/p>\n<p><code>sudo port select --set python python26<\/code><\/p>\n<p>Now if you type<\/p>\n<p><code>$ which python<\/code><\/p>\n<p>You should see<\/p>\n<p><code>\/opt\/local\/bin\/python<\/code><\/p>\n<p>which is a symlink to<\/p>\n<p><code>\/opt\/local\/bin\/python2.6<\/code><\/p>\n<p>Typing the below will now launch the Python2.6 shell editor (ctl + d to exit)<\/p>\n<p><code>$ python<\/code><\/p>\n<p>7. Install required libraries for Scrapy<\/p>\n<p><code>$ sudo port install py26-libxml2 py26-twisted py26-openssl <del datetime=\"2010-09-21T07:29:35+00:00\" cite=\"http:\/\/groups.google.com\/group\/scrapy-users\/browse_thread\/thread\/2917c26ea826af24\">py26-simplejson<\/del><\/code><\/p>\n<p>Other posts recommended installing  py26-setuptools but it kept returning with with errors, so I skipped it.<\/p>\n<p>8. &#8220;Test that the correct architectures are present:<\/p>\n<p><code>$ file `which python`<\/code><\/p>\n<p>The single quotes should be backticks, which should spit out (for intel macs running 10.5):&#8221;<\/p>\n<p><code>\/opt\/local\/bin\/python: Mach-O universal binary with 2 architectures<br \/>\n\/opt\/local\/bin\/python (for architecture i386):\tMach-O executable i386<br \/>\n\/opt\/local\/bin\/python (for architecture ppc7400):\tMach-O executable ppc<\/code><\/p>\n<p>9. Confirm libxml2 library is installed (those really are single quotes). If there are no errors it imported successfully.<\/p>\n<p><code>$ python -c 'import libxml2'<\/code><\/p>\n<p>10. Install Scrapy<\/p>\n<p><code>$ sudo \/opt\/local\/bin\/easy_install-2.6 scrapy<\/code><\/p>\n<p><!--11. Add Scrapy to your Python Path\n\n<code>$ sudo ln -s \/opt\/local\/Library\/Frameworks\/Python.framework\/Versions\/2.6\/bin\/scrapy-ctl.py \/opt\/local\/Library\/Frameworks\/Python.framework\/Versions\/2.6\/lib\/python2.6\/site-packages\/scrapy<\/code>\n\n12. Make the scrapy command available in the shell\n\n<code>$ sudo ln -s \/opt\/local\/Library\/Frameworks\/Python.framework\/Versions\/2.6\/bin\/scrapy-ctl.py \/usr\/local\/bin\/scrapy<\/code><\/del>--><\/p>\n<p>11. Make the scrapy command available in the shell<\/p>\n<p><code>$ sudo ln -s \/opt\/local\/Library\/Frameworks\/Python.framework\/Versions\/2.6\/bin\/scrapy \/usr\/local\/bin\/scrapy<\/code><\/p>\n<p>One caveat for the above, on a fresh computer, you might not have a \/usr\/local\/bin directory so you will need to create it before you can run the above to create the symlink.<\/p>\n<p><code>$ sudo mkdir \/usr\/local\/bin<\/code><\/p>\n<p>13. Finally, type either of the following to confirm that Scrapy is indeed running on your system.<\/p>\n<p><code>$ python scrapy<\/code><\/p>\n<p><code>$ scrapy<\/code><\/p>\n<p>A final final bit&#8230; I also installed <a href=\"http:\/\/ipython.scipy.org\/moin\/FrontPage\">ipython<\/a> from Macports for use with Scrapy<\/p>\n<p><code>sudo port install py26-ipython<\/code><\/p>\n<p>Make a symbolic link<br \/>\n<code>sudo ln -s \/opt\/local\/bin\/ipython-2.6 \/usr\/local\/bin\/ipython<\/code><\/p>\n<p>An article on ipython<br \/>\n<a href=\"http:\/\/onlamp.com\/pub\/a\/python\/2005\/01\/27\/ipython.html\">http:\/\/onlamp.com\/pub\/a\/python\/2005\/01\/27\/ipython.html<\/a><\/p>\n<p>ipython tutorial<br \/>\n<a href=\"http:\/\/ipython.scipy.org\/doc\/manual\/html\/interactive\/tutorial.html\">http:\/\/ipython.scipy.org\/doc\/manual\/html\/interactive\/tutorial.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>+ Here is a step-by-step explaining how I got Scrapy running on my MacBook Pro 10.5 using MacPorts to install Python and all required libraries (libxml2, libxsit, etc.). The following has been tested on two separate machines with Scrapy .10. Many thanks to users here who shared some helpful amendments to the default installation guide. [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"https:\/\/owenmundy.com\/blog\/2010\/09\/how-to-install-scrapy-with-macports-full-version\/\">Read More&#8230;<span class=\"screen-reader-text\"> from How to install Scrapy with MacPorts (full version)<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[42],"tags":[165,78],"class_list":["post-889","post","type-post","status-publish","format-standard","hentry","category-code","tag-code","tag-python"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2ovQg-el","_links":{"self":[{"href":"https:\/\/owenmundy.com\/blog\/wp-json\/wp\/v2\/posts\/889","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/owenmundy.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/owenmundy.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/owenmundy.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/owenmundy.com\/blog\/wp-json\/wp\/v2\/comments?post=889"}],"version-history":[{"count":47,"href":"https:\/\/owenmundy.com\/blog\/wp-json\/wp\/v2\/posts\/889\/revisions"}],"predecessor-version":[{"id":1894,"href":"https:\/\/owenmundy.com\/blog\/wp-json\/wp\/v2\/posts\/889\/revisions\/1894"}],"wp:attachment":[{"href":"https:\/\/owenmundy.com\/blog\/wp-json\/wp\/v2\/media?parent=889"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/owenmundy.com\/blog\/wp-json\/wp\/v2\/categories?post=889"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/owenmundy.com\/blog\/wp-json\/wp\/v2\/tags?post=889"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}