Philadelphia Python Workshop 9/Setup/OSX project dependencies: Difference between revisions

Content added Content deleted
imported>Geography76
No edit summary
imported>Geography76
No edit summary
Line 45: Line 45:
<ol>
<ol>
<li>Click and save these four dependencies to your Desktop:
<li>Click and save these four dependencies to your Desktop:
* https://github.com/abatula/PythonWorkshop-Twitter/archive/master.zip
* http://mit.edu/jesstess/www/BostonPythonWorkshop6/Twitter/httplib2-0.6.0.zip
* http://mit.edu/jesstess/www/BostonPythonWorkshop6/Twitter/simplejson-2.1.6.zip
* http://mit.edu/jesstess/www/BostonPythonWorkshop6/Twitter/python-twitter.zip
* http://mit.edu/jesstess/www/BostonPythonWorkshop6/Twitter/python-oauth2.zip
</li>
</li>
<li>
<li>
Line 57: Line 54:
===Install the Twitter project dependencies===
===Install the Twitter project dependencies===


Unzip the file you just downloaded. Open a command prompt and navigate to the unzipped folder. For example, if you extracted the folder to /home/myname/Desktop/PythonWorkshop-Twitter-master, the command
Each of these 4 dependencies has an installer script that we'll need to run at a command prompt to install the software. '''It is important that the dependencies are installed in the order listed above.''' For each project, start a command prompt and navigate to the Desktop directory where the source code lives. For example, if the httplib2-0.6.0 project was extracted to /Users/jesstess/Desktop/httplib2-0.6.0,

<pre>
<pre>
cd /Users/jesstess/Desktop/httplib2-0.6.0
cd /home/myname/Desktop/PythonWorkshop-Twitter-master
</pre>
</pre>


will change you into that directory, and
will move you into that directory and


<pre>
<pre>
Line 69: Line 65:
</pre>
</pre>


will show you the source code files in that directory. In this directory are five folders: Twitter (the main folder) and four dependency folders (simplejson-3.3.0, python-oauth2-master, httplib2-0.8, and python-twitter-1.0). Three of the dependency subfolders have an installer script that we'll need to run at a command prompt to install the software. For each dependency (in the order: simplejson-3.3.0 python-oauth2-master httplib2-0.8) navigate to the folder using cd. For example:
will show you the source code files in that directory. One of the files is "setup.py", which has a ".py" extension indicating that it is a Python script. Type:
<pre>
cd simplejson-3.3.0
</pre>
to move into the subfolder for simplejson from the main PythonWorkshop-Twitter-master folder. Use the ls command again to display the source code files in the directory. One of the files is "setup.py", which has a ".py" extension indicating that it is a Python script. Type:


<pre>
<pre>
Line 75: Line 75:
</pre>
</pre>


and hit enter to install httplib2. You will need to enter your Mac account password.
type in your password, and hit enter to install simplejson.


To return to this main folder, use the cd command again to move up one directory:
Navigate to the 3 other dependency directories and run

<pre>
cd ..
</pre>


Navigate to the 2 other dependency directories and run


<pre>
<pre>
Line 83: Line 90:
</pre>
</pre>


in all of them to install those dependencies as well.
in all of them to install those dependencies as well.


If you get an error like:
===Download the Twitter project===


<pre>
We've written some skeleton code for the Twitter project already. Download this code so you're ready to start working with it tomorrow:
ImportError: No module named setuptools
</pre>


you need an extra package. Type:
# Right click the following file, click "Save Target as..." or "Save link as...", and save it to your Desktop directory:
#* http://web.mit.edu/jesstess/www/BostonPythonWorkshop6/Twitter.zip
#Find Twitter.zip on your Desktop and double-click on it to "unzip" it. That will create a folder called Twitter containing several files.


<pre>
===Test the Twitter code===
sudo apt-get install python-setuptools
</pre>


Now use cd to move into the python-twitter-1.0 folder. This time we will run the two following commands to install the dependency:
Start a command prompt and navigate to the Desktop/Twitter directory where the Twitter code lives. For example, if the Twitter project is at <code>/Users/jesstess/Desktop/Twitter</code>,
<pre>
python setup.py build
sudo python setup.py install
</pre>

And type in your password when prompted.

===Test the Twitter code===


Within the python-twitter-1.0 folder, run
<pre>
<pre>
python twitter_test.py
cd /Users/jesstess/Desktop/Twitter
</pre>
</pre>


After it runs, it should state that it ran 41 tests on the code, and the final line should say "OK." If your test failed, ask an instructor for help.
will change you into that directory, and


After successfully testing the dependencies, use the cd command again to navigate to the Twitter folder. Use the ls command again to view the files in this folder. One of the files is "twitter_functions.py", which has a ".py" extension indicating that it is a Python script. Open this file in your text editor and find the line that says:
<pre>
<pre>
CONSUMER_SECRET = 'We will give this to you in class :)'
ls
</pre>
</pre>


Change the string to the consumer secret string that we will give you in class. Save the file and go back to the command line. Now type:
will show you the source code files in that directory. One of the files is "twitter_api.py", which has a ".py" extension indicating that it is a Python script. Type:


<pre>
<pre>
Line 113: Line 132:
</pre>
</pre>


at the command prompt to execute the twitter_api.py Python script. You should the text from 20 tweets containing the word "Python" printed to the screen. If you don't, let a staff member know.
at the command prompt to execute the twitter_api.py Python script. You should see the text from 20 tweets containing the word "Python" printed to the screen. If you don't, let a staff member know.


===Success!===
===Success!===