PUDB Error: <no source code available> - python

I'm new to pudb. It run fine for the most-part, but when I try to enter a library it apparently doesn't recognize, I get the following message:
<no source code available>
If this is generated code and you would like the source code to show up here,
add it to linecache.cache, like
import linecache
linecache.cache[filename] = (size, mtime, lines, fullname)
You can also set the attribute _MODULE_SOURCE_CODE in the module in which this function
was compiled to a string containing the code.
I've tried importing 'linecache' and the 'cache' attribute is a dictionary. I've tried creating an entry for the missing module a few times with no success.
Can someone please give an example on an easier and/or practical way to add an unrecognized module to pudb?

The way it worked for me is the following.
I got this message when a piece of code was executed that has been generated on-the-fly. I tracked down the location where the code was generated, and added:
import linecache
linecache.cache[__file__] = (len(source), 0, source, __file__)
(where the source variable corresponds to the generated source)
What I observed after, was that in pudb interactive mode, in the stack list a new item appeared. This new item was preceeding the one that throws the <no source code available> message.
When I navigate on this new item, I can see the generated source.

This answer is inspired from this GitHub issue. A possible workaround is to use the full path of the script.
Quite simply, instead of python script.py, use python /full/path/to/script.py.
This works because some libraries may use chdir to change directories and when that happens, pudb cannot locate the script, resulting in the error.
TIP: To save some keystrokes, you can simply type python $PWD/script.py instead of typing in the full path.

I was having this issue and in my case it was because the package was being installed as .egg, you can circumvent that installing with pip install -e foo_package

Related

Cannot find module "qfi" for running JdeRobot drone_cat_mouse exercise from source

I want to run JdeRobot drone_cat_mouse on my Ubuntu 20.04. I'm using ROS Noetic and has faithfully followed these installation instructions. Everything it told me to test was working properly.
When I first ran roslaunch drone_cat_mouse.launch, there was an import error for teleopWidget and sensorsWidget which I fixed by using relative imports. Then I had an error No module named qfi.
Unlike teleopWidget and sensorsWidget, I couldn't find the qfi module in the JdeRobot/drones source code. So I googled it, and the only relevant result that popped up was this, which led to this link. They said to:
sudo touch /usr/lib/python2.7/dist-packages/qfi/__init__.py
But I ran that command and this happened!
Not even pip has a "qfi" module!
So I thought to check JdeRobot's entire repository. Turns out it was in JdeRobot/base, and that repo is not maintained anymore!
After further digging, there was this issue which basically tells us forget about it and move to the web release! But I can't, circumstances forced me to use the source code option (deliverables are drone_cat_mouse.world and my_solution.py, it's impossible for me to get the former in the docker web version and the latter's format is different between the source code version and the web version).
In a nutshell, how do I fix this qfi module problem so that I can run the exercises from source like these people?
I'm just stupid, as usual. all I need to do was clone https://github.com/JdeRobot/ThirdParty, get the qfi module, copy it to
~/catkin_ws/src/drones/rqt_drone_teleop/src/rqt_vel_teleop/ and replace all qfi imports with its relative import version. All common sense
No errors in terminal, gazebo runs, but somehow the rqt widget for drone vision never appears.
Forget it, I'm giving up on this dumpster fire of a program.
Edit: I did another fresh install, followed the steps, noticed troubleshooting for qfi which required qmake, but same end result
If you're trying to launch drone_cat_mouse there is an issue with the namespace of the RQT widget that occurs when you try to launch it.
Namely, the topics that exist for drone_cat_mouse are prefixed by cat/ or mouse/. But RQT will try to access these topics without the prefix and run into an error. Alternatively, since you have a local install, you can try to run the code manually by running
python my_solution.py
Just make sure the change the area where the DroneWrapper class was called in the following manner:
HAL = DroneWrapper('drone', 'cat/')
Here 'drone' is the name of the node you are creating and 'cat/' is the namespace given to the DroneWrapper Class.

How do I register a custom bundle with zipline?

I am following the tutorial here:
http://www.prokopyshen.com/create-custom-zipline-data-bundle
and trying to set up a custom bundle to get price from custom, non US financial assets. I am stuck on the line that says:
Advise zipline of our bundle by registering it via .zipline/extension.py
My extension.py file is located in the .zipline/ directiory and has the following code:
from zipline.data.bundles import register
from zipline.data.bundles.viacsv import viacsv
eqSym = {
"CBA"
}
register(
'CBA.csv', # name this whatever you like
viacsv(eqSym),
)
I don't get what it means to register the bundle via .zipline/extension.py though? I thought it might mean to just run the extension.py file from my terminal via a:
python extenion.py
but that fails and says:
ImportError: No module named viacsv
How do i register this bundle?
I also followed this tutorial and I must confess this part is a little confusing.
First of all, I don't think it's necessary to run:
$ python extension.py
The error message you get probably comes from the fact that Python cannot find the viacsv.py file in sys.path (the places where it looks for modules, etc.). In the tutorial you mentioned, it's not really clear what to do with this file. As far as I am concerned, I just saved the viacsv.py file in my local site-packages directory. As I am on Linux I put it there ~/.local/lib/python2.7/site-packages but it might different for you. You can run the following python script to find out:
import sys
for dr in sys.path:
print dr
Then I just substituted from zipline.data.bundles.viacsv import viacsv with from viacsv import viacsv in extension.py.
I suspect you might be looking for the wrong place for the extension.py file.
For windows machine, the file is under "~\.zipline\extension.py". In my case, it's under "C:\Users\XXXX\.zipline\extension.py".
I had been looking at zipline folder under conda's site-packages folder, and couldn't find it. Then created an extension.py myself wondering why it's not called.
Check a related post here https://www.quantopian.com/posts/zipline-issue-while-creating-custom-bundle-to-bring-yahoo-data.
Same issue here, #Gillu13 pointed me to this solution.
I installed zipline through conda. So zipline is installed in
home/me/anaconda3/envs/krakenex/lib/python3.6/site-packages
in there you will find zipline/data/bundles and you can put viacsv.py in there...
then
from zipline.data.bundles.viacsv import viacsv
works

AttributeError: 'ModuleSpec' object has no attribute 'load_data_wrapper'

This is a bit long so bear with me.
I am trying to learn both Python and Linux and am very new to both. I am currently doing some reading on deep learning from the following:
http://neuralnetworksanddeeplearning.com/chap1.html
I am attempting to import the mnist_loader package to use the associated data for testing the script that was previously written. However, upon typing import mnist_loader into the Linux command line, I was given the following:
"the program 'import' can be found in the following packages:"
at which point it listed some packages. Because I'm new to Linux and I don't have admin privileges, I decided to go a route that I understood better; that is to create a new python script and simply use the import command within (which has worked in all previous attempts).
I created a python script and tried import mnist_loader and received the following error:
"ModuleNotFoundError: No module named 'mnist_loader'"
I then checked my C drive and found that the file was indeed there. Here is a link to the Git repository where the files may be found:
https://github.com/MichalDanielDobrzanski/DeepLearningPython35
Next I moved on to trying to directly input the path to the file as follows:
import importlib.util
mnist_loader = importlib.util.spec_from_file_location("mnist_loader",r"C:\Users\XXXXXX\Documents\neural-networks-and-deep-learning-master\neural-networks-and-deep-learning-master\src\mnist_loader.py")
training_data, validation_data, test_data = mnist_loader.load_data_wrapper()
However, this produced the following error:
"AttributeError: 'ModuleSpec' object has no attribute 'load_data_wrapper'"
Note: the last line is used to collect the necessary data from the nist files.
I am running out of thoughts at this point and would love some feedback on all my "wrongdoings" up till now.
Thanks in advance!
P.S. It is worth noting that the book uses a package designed for Python 2.X whereas I am using 3.6. The readme provided by the book file location mentioned a different location where a Python 3.6 version could be found which is what I am going with.
Been a while since I have worked with Python, but I have some ideas as to what would cause the specific errors you are seeing. First I would suggest setting a PYTHON_PATH environment variable with the path you have that contains the module you want to import, this does not require administrator privileges fortunately. As for the load_data_wrapper attribute, you might have to do a from from mnist_loader import * to import all the functions inside the mnist_loader module.

Can only import win32com.client with IDLE. What extra work do i need to set up pywin32?

I have a Tkinter program that i use for time management. I decided to have it scan my inbox in outlook to check emails for tags, and then based on the tag, add it to my list of tasks to do for the night.
The code i wrote works just fine, but i'm getting an error when I import win32com.client. I can import it in IDLE, but it is having problems importing when i try to run the code with a .bat file, or double clicking the .py file.
I have found several people with similar problems, but from what i can tell, it's having problems with win32api module, or pywin32
Traceback (most recent call last):
File "my_program_filename.py", line 1, in <module>
import win32com.client
File "c:/Python27/lib/site-packages/win32com/__init__.py", line 5, in <module>
import win32api, sys, os
ImportError: DLL load failed: The specified module could not be found
I'm really confused. When i get the sys.path it's the same with IDLE as it is running from the .py file with the exception of an added "c:/users/username/desktop/timer" for my .py file.
I'm really lost and haven't had to mess with the system path, but I'm not able to figure out what i need to do to fix this.
What do I need to do to get pywin32 working so I can use win32com.client?
Any help is greatly appreciated. Thanks!
IIRC, the problem was attempting to link to the debug build. I think i had to dupe the release build and rename it to be debug or something.
try building release and see if it "just works". if so, you have a direction to explore
this is an issue of not having the correct paths in the sys.path. If you make sure that all of the pywin32 folders are in the sys.path(If you check in IDLE it can show that the folders are included even when they aren't?!?!?).
You also have to make sure you run your code from inside your Python directory or it will fail to import win32api. I also found that if you do anything in a function that uses pywin32 and you accidentally misspell the function when you call it, the whole import fails without telling you your function is misspelled. You can also navigate to the /Python27/Lib/site-packages/win32com/client folder and run makepy.py to make sure the right Object library is installed.
When you run makepy.py, you select the COM object you want to use and it creates packages specific to what you want to use. I don't fully understand why this is, but once i did this and ran my file from the Python folder it worked! There is a more in depth explanation on how to get this working right here.
I found this link to be the solution rather than the win32com/client as indicated above: win32com import error python 3.4
in my case typing in cmd:
python C:\Python27\Scripts\pywin32_postinstall.py -install
I hope this helps

Python ImportError (Cannot import name Variables)

I have done some research on this question and nothing seems to fix it, I suspect I may be accidentally circularly importing somewhere, but this one has stumped me.
This package is a Python IRC Service framework. The issue occurs when dynamically loading a module (via imp.load_source()), and the new module tries to import something from the src folder (Variables.py). It fails with "Cannot import name Variables", yet, it imports another module from the same directory without complaint.
Here is the specific error:
**ERROR: ModLoad(): Unable to load module
/home/sam/workspace/Affinity/bin/../modules/ircd_affinity.py:
cannot import name Variables
**
This is the full file for modules/ircd_affinity.py: ircd_affinity.py, and src/Variables.py: Variables.py
If it helps. browse the entire repository... this (https://github.com/miniCruzer/Affinity/blob/master/src/Affinity.py) module (starting at line 123) loads modules.
I would appreciate if all responses were kept relevant to the specific issue at hand. Yes, it may be tempting to suggest other things I'm doing wrong or otherwise throughout the entire package - I am welcome to suggestions: please e-mail them to me.
Show the full traceback. Look through it for evidence of (attempted) circular import.
Run Python with the -v option ... what does that tell you?
Look at the contents of sys.path and sys.modules just before the error happens.
"**ERROR: ModLoad(): Unable to ..." doesn't look line a Python-raised error. Is that in your code? If so, dig deeper; why is it raised?

Categories

Resources