problem with virtualenv

I'm new to python and also pycharm. I'm trying to install the python-twitter package.

This is what I did:
I create a project, create a virtual environment thorough the interpreter option, and install the python-twitter package. this is no problem. screenshot is attached
Screen Shot 2013-09-17 at 1.49.57 PM.png


And i create a new python file by right clicking the project name, and click new python file

i then write my two lines code:

import twitter #to import the python-twitter package
api=twitter.Api()

the twitter on the first line is detected by code completion after i typed in import t.
however, when i typed twitter on the second line, followed by dot, the code completion doesn't show me any method available to use. It seems like the package doesn't get imported right or something.

The 2 lines of code above fails with the following error:
"/Users/xxx/Desktop/skydrive/xxx Projects/python/virtualenv/twitter/twitter_env/bin/python" "/Users/xxx/Desktop/skydrive/xxx Projects/python/Twitter/twitter.py"
Traceback (most recent call last):
  File "/Users/xxx/Desktop/skydrive/xxx Projects/python/Twitter/twitter.py", line 1, in <module>
    import twitter
  File "/Users/xxx/Desktop/skydrive/xxx Projects/python/Twitter/twitter.py", line 3, in <module>
    twitter.Api()
AttributeError: 'module' object has no attribute 'Api'

Process finished with exit code 1

could someone help a newbie perhaps?
2 comments
Hi Baji,

If you will run inspections (Code->Inspect code) you could see that "import twitter" line have a warning "Import resolves to its containing file".  That means that you import not a twitter module but your file that has the same name. Renaming your file to e.g. twitter1.py will solve your problem.
0

Please sign in to leave a comment.