How to import external modules ?

Hi,

I'm an absolute beginner :) so please be cool

I'm trying PyCharm on a Windows environment and would like to use a well known module : FeedParser (5.3.1 version).

I tried this short code I found here : http://wiki.gcu.info/doku.php?id=codaz:python:parser_des_flux_rss_en_python

  1. !/usr/bin/env python

import feedparser

rss = "http://www.freebsd.org/security/advisories.rdf"
syndication_number = 10
feeds = feedparser.parse(rss)


  1. parse rss xml structure
  2. <channel>
  3.    <title>blabla</title>
  4.    <link>http://blabla</link>
  5.    <description>blabla</description>
  6. </channel>

  7. <item>
  8.    <title>blabla</title>
  9.    <link>http://blabla<link>
  10. </item>

for i in range(1, syndication_number):
    print "%d - %s %s" % (i, feeds.entries[i]['title'], feeds.entries[i]['link'])




Unfortunatly, when I run the program I get an error telling me that Feedparser has not been found.

So I downloaded the .zip file for this module here : https://code.google.com/p/feedparser/

But I don't understand how to use it. I've opened it as a file and copy/paste it in the 'lib' section of the 'External libraries'. But I would prefer to do it cleanly using a repository. So how can I add a repository where PyCharm would search for modules I want to import ?



Thanx
1 comment
Comment actions Permalink
What I would do is:

1) Install virtualenv (venv) and pip into the global Python environment. Virtualenv is a Python tool to manage virtual Python environments unique to each project.  Pip is a Python package manager. some more info

2) For each project, create a new venv for that project. I usually put it right in the project root directory named 'venv'.  
    cd c:\code\proj1
    c:\Python34\Scripts\virtualenv.exe venv
    venv\Scripts\activate
prettyPrint();

3) Install whatever packages you need using pip:
    pip search feedparser
    pip install feedparser
prettyPrint();

4) In PyCharm, add your venv directory as a Python Interpreter in Settings and make it the active interpreter for the project. The editor should now recognize that you have feedparser installed, and you can also create a Run Configuration to run/debug your code directly from PyCharm.

Hope this helps.
0

Please sign in to leave a comment.