UHD import fails - uhd

I build uhd in windows (msvc 14.2, boost 1.72.0). Build works fine. I can run all of the command line utilities (eg rx_samples_from_file) without error.
But in python I cannot import uhd:
>>> import sys
>>> sys.path.append('C:\\Program Files (x86)\\UHD\\bin')
>>> sys.path.append('C:\\Program Files (x86)\\UHD\\lib')
>>> sys.path.append('C:\\Program Files (x86)\\UHD\\lib\\site-packages')
>>> sys.path.append('C:\\local\\boost_1_72_0\\lib64-msvc-14.2')
>>> sys.path.append('C:\\lib\\libusb-1.0.22\\MS64\\dll')
>>> import uhd
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Program Files (x86)\UHD\lib\site-packages\uhd\__init__.py", line 10, in <module>
from . import types
File "C:\Program Files (x86)\UHD\lib\site-packages\uhd\types.py", line 10, in <module>
from . import libpyuhd as lib
ImportError: DLL load failed while importing libpyuhd: The specified module could not be found.
Is there anyway to tell which DLL is not loading? I tried using dependency walker on libpyuhd but it did not show anything missing.

I had a similar issue, in that I could access the hardware via command line utilities or through GnuRadio Companion, but not directly through python (even though GRC is only launching the python files using the same python interpreter). I kept having these DLL issues.
Turns out that the location in sys.path are used by python to look for modules, but if the modules themselves are relying on .dll files, then they use the locations in the environmental variable path. I guess that the fetching of DLLS is handled directly by the OS and not by Python.
You can see the location in Python with os.environ['PATH'] . It should be the same list as by typing PATH the windows command line.
I solved the problem by crating a batch file that added the directories to the path before running python. In your case, you could try adding the directories to it (you would have to see which ones are missing):
#ECHO off
SET PATH=%PATH%;C:\\Program Files (x86)\\UHD\\bin;C:\\Program Files (x86)\\UHD\\lib;C:\\lib\\libusb-1.0.22\\MS64\\dll
python your_python_script.py
the path will be temporarily changed, (don't forget the %PATH% so that it appends the new folders to it) and once you exit the batch file, it will restore back to the default value.
You could also permanently change the path, by going to System Properties → Advanced → Environment variables.

Related

Single executable file created by py2exe not working

I've created a Python app using Pyqt4 to open up a dialog and do some image processing using opencv2. The app is working fine when executing the script as:
python script.py
To create a single executable file for the script, I'm using py2exe with bundle_files = 1 option. It is creating a single exe file but when clicking the file, a console appears stays for few seconds and a pop-up appears saying program has stopped responding.
I'm working on Windows with anaconda. Please help me with this.
Py2exe generates a logfile.txt in the same folder you first-time execute the generated .exe.
Check this logfile to debug.
Most of the time you need to exclude some dll`s and include at least sip-module;
In your setup.py file:
from distutils.core import setup
import shutil, py2exe
opts = {'py2exe': {'compressed': True, "dll_excludes": ["MSVCP90.dll"], "includes" : ["sip"]}}
setup(console=[{"script" : "main.py"}], options=opts)
shutil.rmtree('build', ignore_errors=True) #Remove the build folder
Personally I did not encounter the need to include PyQt4 modules for compilation..
And btw be glad that python is an interpreted language, otherwise you`ll have to worry about linking to libraries on every build (like in cpp.., which is annoying)
Greets Dr Cobra

Trouble importing shared object in Python

I am attempting to import a shared object into my python code, like so:
import bz2
to which I get the following error:
ImportError: ./bz2.so: cannot open shared object file: No such file or
directory
Using the imp module, I can verify that Python can actually find it:
>>> import imp
>>> imp.find_module('bz2')
(<open file 'bz2.so', mode 'rb' at 0xb6f085f8>, 'bz2.so', ('.so', 'rb', 3))
The shared object file is in my PYTHONPATH and my LD_LIBRARY_PATH.
Any insights into why I can't import this shared object? Thanks!
bz2.so is the shared object the provides the bzip functionality (which was written in C) for the python modules. You don't import it directly when you do import bz2 , you are actually importing a python module called bz2 which then uses the .so file.
This usually means you haven't got the development version of the bzip library installed or you don't have a c compiler setup for the pip installer to use to build this for you.
You don't say which linux you are using but the general pattern is look in the package manager for bzip2 dev or devel packages and install those.

Can't import sqldf in one python file while it works in another. Both files are in different folders. How can I set this right?

In one python file when I try from pandasql import sqldf it works. The path for that is
C:\Users\AmitSingh\Anaconda2\python.exe "C:/Users/AmitSingh/PycharmProjects/HelloPython.py/exercise 2"
In another file when I use the same command it gives me the error
ImportError: cannot import name sqldf
The path for this file is
C:\Users\AmitSingh\Anaconda2\python.exe C:/Users/AmitSingh/Desktop/Data/Udacity/Intro_Machine_Learning/ud120-projects/datasets_questions/explore_enron_data.py
I don't understand why? When I write import sqldf the prompt shows sqldf as an autocomplete option. But doesn't work.
By default, you can't. When importing a file, Python only searches the current directory, the directory that the entry-point script is running from, and sys.path which includes locations such as the package installation directory (it's actually a little more complex than this, but this covers most cases).
However, you can add to the Python path at runtime:
# some_file.py
import sys
sys.path.insert(0, '/path/to/application/app/folder')
import file

ImportError: No module named for my code on Readthedocs

I am trying to link my Sphinx documentation with ReadtheDocs. I can build the documentation locally but when I try to have ReadtheDocs automatically generate the documentation I get the following error:
Sphinx Standard Error
Making output directory...
Exception occurred:
File "/var/build/user_builds/mousedb/checkouts/latest/Docs/source/conf.py", line 25, in <module>
from mousedb import settings
ImportError: No module named mousedb
The full traceback has been saved in /tmp/sphinx-err-n_8fkR.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
Either send bugs to the mailing list at <http://groups.google.com/group/sphinx-dev/>,
or report them in the tracker at <http://bitbucket.org/birkenfeld/sphinx/issues/>. Thanks!
My project name is mousedb. I don't understand why I get this import error in the auto-build but not locally.
Update
Based on the comments I think that this is an issue for importing my settings file into a sibling Docs directory. Rather than doing an absolute import (as I had been doing) I should be doing a relative import based on the location of settings.py and conf.py.
I want to import my settings file into my conf.py with the following directory structure:
-mousedb
--settings.py
-Docs
--source
---conf.py
--build
You originally talked about a "local absolute path to my code" and now about setting up relative paths to your code. This probably means you're not using a setup.py file and also not a virtualenv.
In the same directory as Docs/ and mousedb/, add a setup.py:
from setuptools import setup
setup(name='mousedb',
version='0.1',
description="My sample package",
long_description="",
author='TODO',
author_email='todo#example.org',
license='TODO',
packages=['mousedb'],
zip_safe=False,
install_requires=[
'Django',
# 'Sphinx',
# ^^^ Not sure if this is needed on readthedocs.org
# 'something else?',
],
)
After committing/pushing/whatever this file, you can go to your readthedocs settings for your project. Enable the "use virtualenv" setting. This will "nstall your project inside a virtualenv using setup.py install".
The end result is that everything python-related that readthedocs does will have your project in it's sys.path.
The probable cause of your problems is that you run sphinx from within your "root" directory on your local system, where python magically finds the mousedb/ package in your current directory. But readthedocs apparently runs it from within the Docs/ directory and thus cannot find mousedb.

How does localization work in Django?

I have reading some topics of http://docs.djangoproject.com/en/1.3/topics/i18n/localization/
But have not understand what I need to do.
First what I intend to do...
I have created a new App, called "directorio", and now I need to have the capability of translate the data inside some database columns.
my models.py
PS: I have asked for a way of doing this and I have obtained some help from the user "Tommaso Barbugli"
from django.utils.translation import ugettext as _
GENDERS = (('male', _('MALE')), ('female', _('FEMALE')))
class Genders(models.Model):
n_gender = models.CharField(max_length= 60, choices= GENDERS)
After doing this I think I need to do the *.po an *.mo files inside my App directory... I have tried to do:
django-admin.py makemessages -l pt
But is not working, I got this error:
Traceback (most recent call last):
File "C:\Python27\Lib\site-packages\djan
odule>
from django.core import management
ImportError: No module named django.core
C:\xampp\htdocs\djangodir\directorio>djang
Traceback (most recent call last):
File "C:\Python27\Lib\site-packages\djan
odule>
from django.core import management
ImportError: No module named django.core
What I need to do to create the dir "locale\pt\LC_MESSAGES" and the *.po and *.mo files for my App?
Another question I'm developing on windows. I must to install gettext?
Give me some clues, I'm kind of lost.
Best Regards,
you need to install gettext.
out of the docs:
This is only needed for people who either want to extract message IDs or compile message files (.po). Translation work itself just involves editing existing files of this type, but if you want to create your own message files, or want to test or compile a changed message file, you will need the gettext utilities:
Download the following zip files from the GNOME servers http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/ or from one of its mirrors
gettext-runtime-X.zip
gettext-tools-X.zip
X is the version number, we are requiring 0.15 or higher.
Extract the contents of the bin\ directories in both files to the same folder on your system (i.e. C:\Program Files\gettext-utils)
Update the system PATH:
Control Panel > System > Advanced > Environment Variables.
In the System variables list, click Path, click Edit.
Add ;C:\Program Files\gettext-utils\bin at the end of the Variable value field.
You may also use gettext binaries you have obtained elsewhere, so long as the xgettext --version command works properly. Do not attempt to use Django translation utilities with a gettext package if the command xgettext --version entered at a Windows command prompt causes a popup window saying "xgettext.exe has generated errors and will be closed by Windows".