Python syntax error in repr.py when calling help function - python

I am having a very odd problem with Python. Whenever I try to use the built-in help function, I get this error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site.py", line 468, in __call__
import pydoc
File "/usr/lib/python2.7/pydoc.py", line 56, in <module>
from repr import Repr
File "repr.py", line 21
def
^
SyntaxError: invalid syntax
I have manually inspected the aforementioned files, but I don't see the error mentioned. I also tried deleting the .pyc files for the files mentioned in the trceback in the /usr/share/python2.7 directory, but I am still having the issue.
My computer is running Ubuntu 12.10 64 bit.

Do you have a file called repr.py in the current directory? That file is incomplete, and shadows the standard library repr module. You can see from the traceback that the file has no full path, only a local path. Rename it or remove it.
Please, do not just delete .pyc files from your system folders, please reinstall python from packages (using your package manager).

Related

Pyinstaller doesn't recognize docx2pdf library

my issue is that i've been trying to make an exe file with a .py that I created, but it doesn't work. I executed the converted .exe file from the console to see the log and I got this:
Traceback (most recent call last):
File "professors.py", line 10, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 531, in exec_module
File "docx2pdf\__init__.py", line 13, in <module>
File "importlib\metadata.py", line 551, in version
File "importlib\metadata.py", line 524, in distribution
File "importlib\metadata.py", line 187, in from_name
importlib.metadata.PackageNotFoundError: docx2pdf
[6940] Failed to execute script professors
I've been reading about the issue and it seems that pyinstaller doesn't recognize the docx2pdf import. I read in a website that I have to add it in a folder called site-packages, but it is supposed to have another folder inside called pyInstaller, which is not there. I also tried adding the folder manually but it still didn't work. I also tried with the --hidden-imports method but im not sure how to exactly use it.
I will have to apply this to other imports that I have also.
Any ideas? Thanks in advance!
I had a identical issue. I removed lines 7-13 from the docx2pdf module:
try:
# 3.8+
from importlib.metadata import version
except ImportError:
from importlib_metadata import version
__version__ = version(__package__)
and line 119...
print(__version__)
After that, it worked. Modifying the module probably isn't the best solution, and of course I'd recommend backing up the module before modifying it, but I hope it works for you too.

Problem with Pyinstaller when using ITKPython

I am using ITKPython,
My codes are working well in PyCharm with *.py format but after making a standalone *.exe file via PyInstaller some errors occure as follow:
Traceback (most recent call last):
File “RSG_V_0.py”, line 27, in <module>
File “site-packages\itkExtras.py”, line 449, in imread
File “site-packages\itkLazy.py”, line 40, in getattribute
AttributeError: ‘LazyITKModule’ object has no attribute ‘ImageFileReader’
[29316] Failed to execute script RSG_V_0
Would you please show me the way to solve these kind of problems.
By the way, already I test my PyInstaller with a simple print.py, In fact PyInstaller is working correctly without ITK filters.
Thanks
Sina
That is most likely a problem in PyInstaller. Report it on their issue tracker.

Trying to make PLY work for the first time

I'm new to Python and I'm having some problems trying to make PLY works. For now, all I want is to successfully run the example from the PLY homepage.
At first I tried to just download PLY-3.8, put the ply folder in the same directory I saved the example (calc.py) and ran it. The calc.py file is at the C:\Users\...\Python directory and the ply folder is the C:\Users\...\Python\ply, just to make it clearer. But I got an ImportError: No module named 'ply'.
Then I searched for a while, tried to update something called distutils and install the modules through the Windows PowerShell and so on and so forth, but none of that worked and I just reset the whole thing (reinstalling Python and all of that). But then I finally got it to work by simply inserting into the sys.path the directory path where the script I was running (edit: in interactive mode) was, by doing this:
import sys
sys.path.insert(0,'C:\\Users\\ ... \\Python')
This fixed the ImportError but, and this is where I am now, there are a bunch of other errors:
Traceback (most recent call last):
File "C:\Users\...\Python\calc.py", line 48, in <module>
lexer = lex.lex()
File "C:\Users\...\Python\ply\lex.py", line 906, in lex
if linfo.validate_all():
File "C:\Users\...\Python\ply\lex.py", line 580, in validate_all
self.validate_rules()
File "C:\Users\...\Python\ply\lex.py", line 822, in validate_rules
self.validate_module(module)
File "C:\Users\...\Python\ply\lex.py", line 833, in validate_module
lines, linen = inspect.getsourcelines(module)
File "c:\users\...\python\python35\lib\inspect.py", line 930, in getsourcelines
lines, lnum = findsource(object)
File "c:\users\...\python\python35\lib\inspect.py", line 743, in findsource
file = getsourcefile(object)
File "c:\users\...\python\python35\lib\inspect.py", line 659, in getsourcefile
filename = getfile(object)
File "c:\users\...\python\python35\lib\inspect.py", line 606, in getfile
raise TypeError('{!r} is a built-in module'.format(object))
TypeError: <module '__main__'> is a built-in module
Now I have absolutely no idea what to do. I tried to search for a solution but had no luck. I appreciate if anyone can help me out.
I'm on Windows 10, using Python 3.5.0 and iep as my IDE (www.iep-project.org) if these informations are of any importance.
In short: I just want to successfully run the example from the PLY homepage and then I think I can figure out the rest.
EDIT: I found out that if I do:
import inspect
inspect.getfile(__main__)
I get the exact same (last) error from before:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "c:\users\...\python\python35\lib\inspect.py", line 606, in getfile
raise TypeError('{!r} is a built-in module'.format(object))
TypeError: <module '__main__'> is a built-in module
I think this is the culprit, but I still don't know how to fix it.
EDIT 2: I got it to work and answered the question explaining how, but if someone have a more complete answer, I would love to hear it.
To anyone having this problem, I found what was the issue. I still don't know why exactly is like that, so if anyone have a more complete answer to provide I would appreciate (I'm still a newbie at Python).
Anyway, it seems this code can't be executed in Interactive mode, it needs to be executed as a script. To do that on IEP it's Run > Run file as script or Ctrl+Shift+E. On IDLE you need to Open... the file (Ctrl+O) and then Run Module (F5).
As to why it can't be executed in Interactive mode, here's a little bit about the difference between interactive mode and running as script from the IEP wizard:
Interactive mode vs running as script
You can run the current file or the main file normally, or as a script. When run as script, the shell is restared (sic) to provide a clean environment. The shell is also initialized differently so that it closely resembles a normal script execution.
In interactive mode, sys.path[0] is an empty string (i.e. the current dir), and sys.argv is set to [''].
In script mode, __file__ and sys.argv[0] are set to the scripts filename, sys.path[0] and the working dir are set to the directory containing the script.
That explains a bit about why the inspect.getfile(__main__) was throwing an error: the __main__ had no attribute __file__. And also why I had to insert the current directory into sys.path: sys.path didn't had the current directory in interactive mode.
I hope this helps someone.

RabbitVCS does not work because of python error

Hello
I cannot start running rabbitvcs on openSUSE 11.3 64bit.
I tried to run test.py file which is located in rabbitvcs folder.
It returns the following errors:
jenea#linux-nguv:/usr/lib/python2.6/site-packages/rabbitvcs> python test.py
Traceback (most recent call last):
File "test.py", line 26, in <module>
import lib.helper
File "/usr/lib/python2.6/site-packages/rabbitvcs/lib/__init__.py", line 23, in <module>
from rabbitvcs.lib.log import Log
ImportError: No module named lib.log
PS: I know that is not quite programming question but it seems to me that error occurs because of some paths or settings.
Unfortunately I've no idea where to dig.
Although stupid the answer is the following:
There were two folders where rabbitvcs was intalled. The first was in /usr/lib/rabbitvcs and the second was in /usr/lib64/rabbitvcs. I'm not sure why there was described issue but after I deleted rabbitvcs folder in /usr/lib64 it started to work normally.

py2exe + pywin32 MemoryLoadLibrary import fail when bundle_files=1

I have created a simple program which uses pywin32. I want to deploy it as an executable, so I py2exe'd it. I also didn't want a huge amount of files, so I set bundle_files to 1 (meaning bundle everything together). However, when I attempt running it, I get:
Traceback (most recent call last):
File "pshelper.py", line 4, in <module>
File "zipextimporter.pyc", line 82, in load_module
File "win32.pyc", line 8, in <module>
File "zipextimporter.pyc", line 98, in load_module
ImportError: MemoryLoadLibrary failed loading win32ui.pyd
In my setup script, I tried doing packages=["win32ui"] and includes=["win32ui"] as options, but that didn't help. How can I get py2exe to include win32ui.pyd?
I don't have this problem if I don't ask it to bundle the files, so I can do that, for now, but I'd like to know how to get it to work properly.
Are you sure that the problem is that win32ui.pyd is not included? The stack trace isn't exactly the same as noted in the wiki, but check this out: http://www.py2exe.org/index.cgi/Py2exeAndWin32ui.
The work-around that has worked best so far is to simply re-implement the pywin32 functions using ctypes. That doesn't require another .pyd or .dll file so the issue is obviated.
Do care to try out PyInstaller? I've used it both on Windows 7 and Ubuntu 10.04 and it worked like magic, even when I compiled to .pyd on Windows.
I've been able to bundle all sorts of applications that I've developed with it.
I have the same problem trying to bundle psutil with py2exe. Here is what I found so far.
Traceback (most recent call last):
File "wx_gui.py", line 43, in <module>
File "zipextimporter.pyc", line 82, in load_module
File "psutil\__init__.pyc", line 85, in <module>
File "zipextimporter.pyc", line 82, in load_module
File "psutil\_psmswindows.pyc", line 15, in <module>
File "zipextimporter.pyc", line 98, in load_module
ImportError: MemoryLoadLibrary failed loading _psutil_mswindows.pyd
I get this traceback when bundle_files = 3. zipfile may be specified or may be None, I still get the problem.
First, I thought this was a missing dll because of this page:
http://www.py2exe.org/index.cgi/ProblemsToBeFixed
I've copied all the dlls I found in Python27 into the same directory as the executable and added that directory path to os.environ['path']. That didn't worked.
Then I tried to import my package directly from site-packages.
I've replaced the whole sys.path of my compiled executable with my normal sys.path
sys.path = [r'C:\Python27\Lib\idlelib', ...]
I think the .pyd module got imported but Visual c++ threw me this really ugly error message:
Runtime Error!
Program: {path}.exe
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
I suggest you try to replace the whole sys.path to see if it is working. If it is, you could always make your single executable write the necessary module into a temp directory and add it to your path. If not, I feel like this problem is going to be hard to solve.

Categories