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
import feedparser
rss = "http://www.freebsd.org/security/advisories.rdf"
syndication_number = 10
feeds = feedparser.parse(rss)
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
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
- !/usr/bin/env python
import feedparser
rss = "http://www.freebsd.org/security/advisories.rdf"
syndication_number = 10
feeds = feedparser.parse(rss)
- parse rss xml structure
- <channel>
- <title>blabla</title>
- <link>http://blabla</link>
- <description>blabla</description>
- </channel>
- <item>
- <title>blabla</title>
- <link>http://blabla<link>
- </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
Please sign in to leave a comment.
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'.
3) Install whatever packages you need using pip:
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.