tweepy "undefined variable" errors - python

I am new to both python and Aptana.
I am trying to use the tweepy package in python. I have the following code (from python's site):
import tweepy
user = tweepy.api.get_user('twitter') # "undefined variable" error occurs on this line
print user.screen_name
print user.followers_count
for friend in user.friends():
print friend.screen_name
I get an "Undefined variable from import: get_user". The code actually runs fine with no errors and produces the expected results. I googled and found how to resolve the undefined variable error, but it seems like a hack-a-round. In sum, that link says to add "get_user" to globals in the preferences.
Being new to both Python and Aptana, I just wanted to check to see if that is the best way to resolve it....it just seems like a hack. When I change "tweepy.api.get_user" to "tweepy.api.public_timeline" I get the same error and thus will have to manually add "public_timeline" to the globals....It doesn't seem like the correct way when you have to manually configure each variable.
thanks!

If you would like to not be warned about this you may exclude the warning:
goto Window -> Preferences -> PyDev -> Editor -> Code Analysis
Click on the Undefined tab and add get_user to the textbox. That will clear up your warning.
Andrew

I had a Problem similar to your case (also using PyDev with Aptana).
I upgraded Aptana and PyDev with the following instructions:
Update PyDev on Aptana
after the upgrade PyDev worked just fine for me :)

Related

Installed Python 3.10.2 and now my Pip installs are not being found

Everything in my code was working perfectly fine up until I decided I wanted to utilize match-case in Python. Find out its only a thing in 3.10+, so I quickly install it and change it to be the interpreter in command palette.
Then I try to run my code same as before, and I'm not sure what changed but my Keyboard import is giving me 'Import "keyboard" could not be resolved'. Issues. The same issue was actually present as well with the 'from nis import match' module.
I installed keyboard initially using 'pip install keyboard' when running my 3.9 version, and legit everything was fine. This all started after I installed 3.10 (which I did from Pythons website yes); and I did add to PATH, but I dont think that would have any impact on my imports in VScode.
Confused as heck right now, please look at my screenshots for clearest explanation of what I'm facing.
Import could not be resolved
.
Module Not Found Error
.
pip3.10 show keyboard
.
My interpreter list from command palette
Any and all help appreciated, I'm extremely confused and think I've tried it all now
New Python versions use new site-packages folders. You need to reinstall everything. This is why poetry, pipenv, or requirements.txt are used
I think the linter-like extension/whatever Pylance is is the problem. Why? Because as we've tried, pip install keyboard and pip install --upgrade keyboard just confirm that the requirement is satisfied and the latest version of keyboard is already installed.
What I did was change Pylance's settings. Yes, it's not an actual error (with the code), but Pylance's problem. It just didn't see enough files in the keyboard package to satisfy its hunger, or Microsoft was just too lazy to pass more checks and update it accordingly, because however it happened, when I tried changing the setting to display an "error" at "missing imports" for fun, it didn't show errors or the default "warning" but "none", because I had run the file before I changed it back to display an error (maybe Pylance observed that when the file was run, there was no ModuleNotFoundError, and so stopped showing the warning).
I better shut now, because the setting I changed/overrode by adding it in settings.json is:
"python.analysis.diagnosticSeverityOverrides": {"reportMissingImports":"none"}
which is in:
{
...,
...,
...,
"python.analysis.diagnosticSeverityOverrides": {"reportMissingImports":"none"}
}
Here is a list of keys like "reportMissingImports" whose values you can change. These are the allowed values for the keys in python.analysis.diagnosticSeverityOverrides:
error (red squiggle)
warning (yellow squiggle)
information (blue squiggle)
none (disables the rule)
You would want to change their values only if you want to change their behaviour.
You can find settings.json by its path or by going to the settings GUI and clicking on any "Edit in settings.json" link-like button. You can also make settings.json open instead of the GUI by default.
Now, you won't see any more warnings when you import modules and can code without being anxious about the stupid warning.
Wow, So as it turns out, a solution I tried previously, to no avail is now working to solve this bizarre issue.
Simply put, I once again went to Command Palette (Ctrl+Shft+P), and looked through my interpreters I had to see what could be wrong.
Decided to click on the 'recommended' option I assumed I had been running this whole time. Turns out I was using this 'third' option as shown in the screenshot (the one not highlighted ofcourse); and it's the reason my module installs were being found on my machine, but not by the interpreter; as such giving me errors and not running the module for the program.
Simple error, but thanks to those who did help.

Error when importing Dialogflow in Python

I downloaded a project in which dialogflow is used, from a repo. However, it showed an error on my pycharm "run". The error itself says
django.core.exceptions.ImproperlyConfigured: The included URLconf 'quiniela.urls' does not appear to have any patterns in it.
But I have had that error show on my pycharm even when the error has nothing to do with it. For instance, if I make an integer variable and try to print it, it would show that exact error, which clearly isn't it, the error would be not casting the integer and trying to print it. So, what I'm saying is, that error appears when ANY error exists, so I usually ignore it and that's my problem to fix later, but that's not this question.
I tracked the error, and found that whenever I comment the line import dialogflow (and every line that uses dialogflow) in my views.py, the error disappears. If I uncomment just that import dialogflow, again it fails. Why would that be? If I go to interpreter settings, I see that the package dialogflow is installed, and if I try to install it, it says it's already installed, so that is not the problem.
Why do you think it could fail to import dialogflow? The dialogflow version is 0.7.2, and the python version is 3.6, and I'm using Windows 10.

"No Module named..."-error in editor despite code appearing to work

I've been struggling for quite some time trying to import a module from a molder in a separate directory on my computer for a python project. Currently the code seems to work, but Pycharm is still giving me errors that the module cannot be found. Despite this, if I run the code it seems to do what is intended.
What I have is essentially this:
import sys
sys.path.append(r'D:\Progam\bin')
import foo
Where foo is a module found in D:\Progam\bin, and it's warning me that there is no module named foo. Considering how much issue I've for some reason had to get this working I'm hesitant to just ignore the warning if there's some underlying problem
Anyone have any idea what's happening here?
Because the file isn't in your path globally, your IDE isn't recognizing that it is then valid during execution. It would probably be a security issue if it were adding files to its path from potentially unknown code.
You could either add that directory to your path via CMD like so:
set PATH=%PATH%;C:\your\path\here\
Or just ignore the error.
EDIT: Ignore that, I'm being a sleep deprived dumbass. Take a look at:
how to manage sys.path globally in pycharm
(Thought this edit would be slightly more useful than me just deleting my answer)

Pandas import error when debugging using PVTS

I am dealing with a very silly error, and wondering if any of you have the same problem. When I try to import pandas using import pandas as pd I get an error in copy.py. I debugged into the pamdas imports, and I found that the copy error is thrown when pandas tries to import this: from pandas.io.html import read_html
The exception that is throwns is:
un(shallow)copyable object of type <type 'Element'>
I do not get this error if I try to straight up run the code and not use the PVTS debugger. I am using the python 2.7 interpreter, pandas version 0.12 which came with the python xy 2.7.5.1 distro and MS Visual Studio 2012.
Any help would be appreciated. Thanks!
This is a limitation of the way PTVS detects unhandled exceptions - it can't see the except-block that's going to catch this exception because it is in the code that is eval'd from a string. See the bug in the tracker for more details.
As a workaround, disable "Debug standard library" checked in Tools -> Options -> Python Tools -> Debugging - this should cause the exception to be ignored.
I had the same problem for a while, disabling "Debug standard library" didn't help, then I downloaded the latest version of Python (3.4), pip installed the libs (for example NLTK), and it worked!
I had a system crash while developing a PTVS app and then ran into this problem, re-running the Intellisense 'refresh DB' cleared it.
I faced the same issue, but just hitting 'Continue' will cause it to be ignored and the code execution will proceed in the usual way.
Or you could uncheck the "Break when this exception type is user-handled" option that comes up in the dialog box displaying the error.

Pycharm code completion works, but inserts unresolved references

Using PyCharm 3.0.1 Community the code completion works fine, but when I e.g. compelete to a method to one of the parents classes, the inserted method name then gets marked as an unresolved reference. What am I missing?
Details:
I am new to PyCharm, and test it on a (unified installed) Plone 4.3.2. The interpreter from the Installation is selected automatically, and I add the zinstance/bin/zopepy script for buildout.
I then open Products.CMFPlone-4.3.2-py2.7.egg/Products/CMFPlone/SkinsTool.py and then type
x = SkinsTool
at the bottom of the file. The code completion offers me manage_changeProperties (and shows PropertyManager). I select this, so that the line now says
x = SkinsTool.manage_changeProperties
The manage_changeProperties part is marked though. Hovering over the marked 'manage_changeProperties' now shows
Unresolved attribute reference 'manage_changeProperties' for class 'SkinsTool'
Is this a bug or am I doing something wrong (e.g. with importing the project)?
Edit: Following vape's advice I also tried on an instance. Same problem:
Auto-complete works fine:
But then the reference is unresolved:
This test was also done with 3.0.1 Professional.
Edit 2: The strucuture is the one of a standard plone installation: structure.txt. I have opened the topmost plone.4.3.2 folder.
Cheers,
Joerg
This is likely because there was an error when pycharm generated the skeletons for the plone library. Unless this is a bug, the only way to solve your problem is to delete the .idea folder inside your project. After doing so, reopen the project from the command line using charm <your project dir>. In case you have not made a command line tool for pycharm yet, this is how you do it:
Ok, the bug is fixed:
https://youtrack.jetbrains.com/issue/PY-11401
The next release will hopefully contain the fix, until then I compiled my own version.
Two things to note:
Link (or copy) the folder 'help' from the official community release into the intellij-community/python directory.
comile it from that python directory using 'ant -Didea.build.number=140.1332' (I think the actual number doesn't matter)
The result is in intellij-community/out/pycharmCE/artifacts

Categories