ImportError: No module named pyqt_ui.qt_translator - python

I'm attempting to package a python application (Mnemosyne) using py2app (I didn't write the software; I am only attempting to package it).
I have built the application with py2app:
sudo python setup.py py2app
and copied the qt_menu.nib directory into the Resources directory.
When I then attempt to launch the application:
./dist/Mnemosyne.app/Contents/MacOS/Mnemosyne
I get this error:
ImportError: No module named pyqt_ui.qt_translator
I haven't been able to figure out what to add to the "includes" to ensure qt_translator is included.
I read the list of PyQT modules but I couldn't find which module I need to include to get qt_translator. I learned that there is a QTranslator class in the QtCore module, but including PyQt4.QtCore doesn't help, nor does PyQt4*.
The line in the code that seems to be causing this is:
mnemosyne.components.insert(0,
("mnemosyne.pyqt_ui.qt_translator",
"QtTranslator"))

The class you are missing is part of the package that you download when you download the Mnemosyne tarball it is in the folder mnemosyne/pyqt_ui file name qt_translator.py you need to extract the entire tarball and cd into it in terminal then use py2app.

Related

Cant import local module

So I am trying to use this repository on my computer but I cant seem to import a local module (Agent.pyx) and use functions from that file. The error I get is:
ModuleNotFoundError: No module named 'RLAgent.Agent
Screenshot of error
Link to repository
You have to install the package manually
Since Agent.pyx is a .pyx file, you will need to first build it. The README file in the linked repo also mentions this. So you need to move to the RLAgent directory and execute the setup instruction as:
cd RLAgent
python3 setup.py build_ext --inplace
This will build the required .c and .so file which will then enable it's import in other files such as Train.py which is where the import is throwing an error.

Correct way to link to a python file

I am writing a code organized in some (several) files. For the sake of organization of folders and the CMakeLists.txt, a pythonlibs folder is created during the build process, and some links to python files are created to libraries in the /build/src/XXXX/ folder.
In the python file, I add to the python path:
sys.path.insert(1,'/opt/hpc/softwares/erfe/erfe/build/pythonlibs')
import libmsym as msym
When I run the main python file, there is this one library lybmsym that fails with:
import libmsym as msym
File "/opt/hpc/softwares/erfe/erfe/build/pythonlibs/libmsym.py", line 15, in <module>
from . import _libmsym_install_location, export
ImportError: attempted relative import with no known parent package
I created a link using cmake, but I believe it does use the ln command (tried both hard and symbolic). Is there a way to prevent this behavior without changing the library itself, just another way to create this link?
Thanks.

How to fix invaild module when using pyinstaller

I am trying to compile my python file to executable file using pyinstaller.
I put all the dependent packages and the source python file in one folder.
And I tried pyinstaller --onefile [my python file name].py
It succeeded to build the exe file. However, the exe file fails to run and I checked the warn-[my python script name].txt, there is one invalid module from which I imported the class to my python code.
In my code, I also imported another module, it was working.
from autobench.inst import power, func_gen
from autobench.i2c.aa_i2c import AAreadWrite
invalid module named autobench.i2c.aa_i2c - imported by C:\Users\jgou\Desktop\test\AP711T_OTP_Program.py (top-level)
Autobench and inst and i2c are folders. Power, func_gen and aa_i2c are python files (.py), AAreadWrite is class in aa_i2c file.
Please suggest what is wrong and how to fix this one. Thanks.

python: package doesn't install correctly, setup.py and __init__.py

I have written the beginnings of a package that I would like to distribute, but I am having issues. When I place the sample_test.py in the primary directory, the script runs just fine. When I attempt to create a distribution and run it sample_test.py from anywhere, it doesn't work: ImportError: No module named 'script_functions'.
To install, I am running python setup.py sdist then python setup.py install. Both of these execute without error. Also, to keep from 'polluting' my core python environment, I am creating a new virtual environment and installing to that.
The moog_visa.py and moog_daqmx.py files contain classes that are used by script_functions.py. The hw_test_runner.py and script_functions.py contain simple functions that I wish to make available in my python environment. I'm not sure if this is relevant...
Directory structure:
\hw_test_runner
\examples
\sample_test.py
\hw_test_runner
\__init__.py
\hw_test_runner.py
\moog_daqmx.py
\moog_visa.py
\script_functions.py
\setup.py
My setup script contains:
from setuptools import setup
setup(name='hw_test_runner',
version='0.12',
description='Scriptable hardware test suite',
author='me',
author_email='xxx#XXX',
url='https://my_url.com',
packages=['hw_test_runner'],
install_requires=['numpy', 'pyvisa', 'PyDAQmx']
)
And init.py:
from hw_test_runner.script_functions import *
from hw_test_runner.hw_test_runner import *
In hw_test_runner.py:
from hw_test_runner.script_functions import *
<... more code below ... >
In `script_functions.py:
from hw_test_runner import moog_visa
from hw_test_runner import moog_daqmx
<... more code below ... >
I have tried various incarnations of the import statement within the __init__.py file, but haven't gotten anything working. I suspect that there is one line off somewhere that I just don't have the experience to easily spot.
Edit - More Information
After playing around a bit on the command line, I haven't found the problem, but I believe that the issue may lay with PyCharm. I can execute sample_test.py on the command line but not within PyCharm. PyCharm is set up to use the appropriate virtual environment, but there is apparently still something else missing.

Add a Python module to a Google App Engine project

I'm trying to use the feed-parser module for this project im working on. When I upload the files to App Engine and I run the script it comes back with the error that the there is no module named feed-parser.
So I'm wondering if and how can I install this module on App Engine, so that I can fix this error and use RSS.
Error:
Traceback (most recent call last):
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 85, in LoadObject
obj = __import__(path[0])
File "/base/data/home/apps/s~vlis-mannipulus-bot/1.391465315184045822/main.py", line 7, in <module>
import feedparser
ImportError: No module named feed parser
Development 1:
So I've tried installing the module in the lib directory i created(in this fail example i forgot the /lib at the --prefix=..). And i get PYTHONERROR as is shown in the shell. Ive done some research on python paths and the solutions i tried didn't work for me.
kevins-MacBook-Pro-2:~ KevinH$ cd /Users/KevinH/Downloads/feedparser -5.2.1
kevins-MacBook-Pro-2:feedparser-5.2.1 KevinH$ sudo python setup.py install --prefix=/Users/KevinH/Documents/Thalia\ VMbot/Thalia-VMbot/
Password:
running install
Checking .pth file support in /Users/KevinH/Documents/Thalia VMbot/Thalia-VMbot//lib/python2.7/site-packages/
/usr/bin/python -E -c pass
TEST FAILED: /Users/KevinH/Documents/Thalia VMbot/Thalia- VMbot//lib/python2.7/site-packages/ does NOT support .pth files
error: bad install directory or PYTHONPATH
You are attempting to install a package to a directory that is not
on PYTHONPATH and which Python does not read ".pth" files from. The
installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:
/Users/KevinH/Documents/Thalia VMbot/Thalia-VMbot//lib/python2.7/site- packages/
and your PYTHONPATH environment variable currently contains:
''
Here are some of your options for correcting the problem:
* You can choose a different installation directory, i.e., one that is
on PYTHONPATH or supports .pth files
* You can add the installation directory to the PYTHONPATH environment
variable. (It must then also be on PYTHONPATH whenever you run
Python and want to use the package(s) you are installing.)
* You can set up the installation directory to support ".pth" files by
using one of the approaches described here:
https://pythonhosted.org/setuptools/easy_install.html#custom- installation-locations
Please make the appropriate changes for your system and try again.
Then i tried with the "pip" command but then i get this:
can't open file 'pip': [Errno 2] No such file or directory
According to what I have read "pip" should be a default program installed with python 2.7 and up. So to be sure i did install python3.5 and ran it with that and still get the same error. I typed this with both pythons:
kevins-MacBook-Pro-2:feedparser KevinH$ python3 pip -m install feedparse
--
Not sure if this would work, but via terminal i went to the default directory where feed parser has been installed on my system and copied it to the lib directory i made. Then I've created the config file with the following:
from google.appengine.ext import vendor
# Add any libraries installed in the "lib" folder.
vendor.add('lib')
Deployed it and im still getting the same error as above no module named feeedparser.
Apologies if im doing something stupidly wrong, im still in the learning process.
The App Engine documentation that explains how to add third party modules is here
In summary, you will need to add a folder, usually named 'lib', to the top level off your app, and then install feedparser into that folder using the commands described in the documentation. You will also need to create an appengine_config.py file as descibed in the documentation.
Note that not all third party packages can be uploaded to App Engine - those with C extensions are forbidden. Feedparser looks OK to me though.
EDIT: further comments based on edit "development1" to the question.
Your appengine_config.py looks good.
You "lib" folder should be your application folder, that is the same folder as your app.yaml and appengine_config.py files.
You need to install the feedparser package into the lib folder. The Google docs recommend that you do this by running the command
pip install -t lib feedparser
This command will install the feedparser package into your lib folder.
You need to install and run a version of pip that works with Python2.x - the Python3 version will create a version of feedparser that only runs under Python3.
If you can't install a pip for Python2 this question might provide the right solution, otherwise I'd suggest you ask a separate question about how to install feedparser into a custom install directory on a Mac.I don't have a Mac so I can't help with this.
Once you have feedparser installed in your lib folder, verify that your app works locally; in particular verify that it's using your lib/feedparser installation: try logging feedparser.__file__ after importing feedparser to check the location of the file being imported.
Once everything is working locally you should be able to upload to GAE.
So in summary, your appengine_config.py looks good, but you need to make sure that the right version of feedparser is installed into the lib folder in your app folder before uploading to App Engine.

Categories

Resources