I am having issues getting python to import the _analog_swig gnuradio module in order to run gnuradio code on a Windows 8.1 64bit machine.
Some background: I am running Python 2.7.10 (installed in C:\Python27) and have installed the latest gnuradio binary (v3.7.11.1/v1.3 64-Bit Any CPU) from here: http://www.gcndevelopment.com/gnuradio/downloads.htm. I have installed gnuradio to C:\Program Files\GNURadio-3.7 .
I can run gnuradio companion and run flowgraphs from GRC successfully (which calls "C:\Program Files\GNURadio-3.7\bin\run_gr.bat" gnuradio-companion.py).
I have added & verified the following system variables are set:
Path: C:\Program Files\GNURadio-3.7\bin
PYTHONPATH: C:\Program Files\GNURadio-3.7\lib\site-packages
GRC_BLOCKS_PATH: C:\Program Files\GNURadio-3.7\share\gnuradio\grc\blocks
Now to the problem: If I run e.g. CMD and type:
python C:\test\top_block.py
I am returned the following ImportError:
File "C:\test\top_block.py", line 22, in <module>
from gnuradio import analog
File "C:\Program Files\GNURadio-3.7\lib\site-packages\gnuradio\analog\__init__.py", line 33, in <module>
from analog_swig import *
File "C:\Program Files\GNURadio-3.7\lib\site-packages\gnuradio\analog\analog_swig.py", line 17, in <module>
_analog_swig = swig_import_helper()
File "C:\Program Files\GNURadio-3.7\lib\site-packages\gnuradio\analog\analog_swig.py", line 16, in swig_import_helper
return importlib.import_module('_analog_swig')
File "C:\Python27\lib\importlib\__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named _analog_swig
The folder content of C:\Program Files\GNURadio-3.7\lib\site-packages\gnuradio\analog is as follows:
Comparing this to the folder content on a linux machine, which has a working install of gnuradio that works with python as I want it:
The difference seems to be that the folder in windows contains only a _analog_swig.pyc file, whereas the folder in linux contains a _analog_swig_.so file.
Any idea why the _analog_swig module can apparently not be imported in windows?
My plan is to be able to run gnuradio code directly from my python interpreter and being able to create compiled gnuradio executables so any help on how this could be fixed is much appreciated.
I've been struggling with this for the past few days, but I finally figured it out. I was trying to run GnuRadio Companion generated code in IDLE and also in PyCharm. I kept failing miserably with this same error. I finally figured it out:
-As Flexo says, the PYD file (_analog_swig.pyd) is actually a Windows DLL. The error makes it sound like Python is not finding that file, but that is not at all what was happening. The PYD file, being a DLL, has dependencies itself. Python is able to find _analog_swig.pyd just fine, but it could not find the DEPENDENCIES of that library.
-To verify if that's what wrong in your installation, download and use DependencyWalker (Google it) to check if your system can find the dependencies to _analog_swig.pyd.
-The fix for me was to add the GnuRadio-3.7/bin folder to my PATH environment variable. Inside that folder are a number of DLLs that the _analog_swig.pyd library needs to load. If you don't have the folder in your PATH, the module will fail to load in Python and throw the error you see above.
-I see that you verified that this folder is in your PATH, so this is apparently not the same problem, although your symptoms are exactly the same as mine. i.e. the GRC code would run just fine when you start with "run_gr.bat", but not when you run from a normal CMD window.
Hopefully that helps someone else that wants to use GNURadio Python code on Windows.
Friend,
As you mentioned, the GNU Companion calls \bin\run_gr.bat gnuradio-companion.py. That batch script does quite a bit of work on windows environment variables (try opening it in a text editor if you're curious).
In a sense, the run_gr.bat script puts together a temporary, custom python workspace for gnuradio so it can import anything it needs. It receives python scripts to run in this environment as command line arguments; hence, you can use it to run any GNU radio python code you want in your windows command prompt. Generally, you would call
<gnuradio_install_path>\bin\run_gr.bat <gnu_radio_code>.py
To test your import, you can try
# test.py
from gnuradio import analog
try calling the following from the command prompt, in the test.py directory:
<gnuradio_install_path>\bin\run_gr.bat test.py
Related
So, I've had some trouble setting up my application through Inno setup Compiler, at first I assumed it was a problem within Inno itself but on further inspection I think it is my actual exe. I am able to create a working exe file that runs my program properly but only on my own pc. I am able to create the setup file that also works through Inno setup but it only works on my own pc. I have sent both the actual exe file and the Inno setup file to another computer and downloaded it there and ran it, both meet the same "Fatal Error: failed to run script tk_app.py". Therefore, the problem must be that I have not been able to pavkage the app properly with pyinstaller.
My prgoram has 5 files in total (all in the same folder): main.py, file1.py, file2.py file3.py, tk_app.py
All of them importing each other and using python libraries. I know that pyinstaller supports librarires such as pandas, tkinter and many more without needing the --hidden-impoort= command and that it will pick up all files within the program if there are files that are importing each other.
So I use the file tk_app.py (which contains my tkinter UI and imports main.py which then goes onto import file1.py which import another file so on)
The pyinstaller command line I use to make the exe is as follows:
PS C:\Users\ripta\Desktop\CODING\CSV_Upload> pyinstaller -w --hidden-import=bs4 --hidden-import=fake_useragent --hidden-import=urllib.prase --hidden-import=urllib.request --hidden-import=os --hidden-import=pandas.io.parsers --icon=trademark_icon.ico --onefile tk_app.py
My question is, will pyinstaller tell me when it needs a given --hidden-import='name' when running becuase it doesn not throw up any errors and does produce a spec file, a build folder and a dist folder containing the exe file.
I have noticed that it throws up WARNINGs or Exceptions (also not sure why it mentions django as I do not import or use it at all inthe application) :
59182 INFO: Loading module hook 'hook-django.db.backends.py' from 'c:\\users\\ripta\\appdata\\local\\programs\\python\\python36-32\\lib\\site-packages\\PyInstaller\\hooks'... 61711 WARNING: Hidden import "django.db.backends.__pycache__.base" not found! 61712 INFO: Loading module hook 'hook-django.py' from 'c:\\users\\ripta\\appdata\\local\\programs\\python\\python36-32\\lib\\site-packages\\PyInstaller\\hooks'... Traceback (most recent call last): File "<string>", line 21, in walk_packages File "c:\users\ripta\appdata\local\programs\python\python36-32\lib\site-packages\django\contrib\gis\admin\__init__.py", line 5, in <module>
Or show Hidden-import not found (Of imports I have no idea about):
149329 WARNING: Hidden import "pkg_resources.py2_warn" not found! 149330 WARNING: Hidden import "pkg_resources.markers" not found!
The fact that the script fails to run on any other computer besided my own leads me to think that it must be lacking a dependency that is only found on my computer, therefore I am not using pyinstaller correctly but am not too sure where exactly I am making the mistake.
First I've uninstalled Setuptools and reinstalled it with specific version. Then, I've imported pkg_resources.py2_warn as hidden import :
pip uninstalled setuptools
pip install --upgrade 'setuptools<45.0.0'
pyinstaller --hidden-import='pkg_resources.py2_warn' tk_app.py
It worked for me.
I am trying to use Openpose from windows and i need to run .py file. But i couldn't find any command to install pyopenpose module So where can I find pyopenpose module?
I tried this command on cmd:
C:\openpose\examples\tutorial_api_python>python 01_body_from_image.py
I get the error :
Error: OpenPose library could not be found. Did you enable `BUILD_PYTHON` in CMake and have this Python script in the right folder?
Traceback (most recent call last):
File "01_body_from_image.py", line 26, in <module>
raise e
File "01_body_from_image.py", line 17, in <module>
import pyopenpose as op
ModuleNotFoundError: No module named 'pyopenpose'
The error in general is that PyOpenPose cannot be found (an error similar to: ImportError: cannot import name pyopenpose). Ensure first that BUILD_PYTHON flag is set to ON. If the error persists, check the following:
In the script you are running, check for the following line, and run the following command in the same location as where the file is.
Ubuntu/OSX:
sys.path.append('../../python');
ls ../../python/openpose
Check the contents of this location. It should contain one of the following files:
pyopenpose.cpython-35m-x86_64-linux-gnu.so
pyopenpose.so
If you do not have any one of those, you may not have compiled openpose successfully, or you may be running the examples, not from the build folder but the source folder. If you have the first one, you have compiled PyOpenPose for Python 3, and have to run the scripts with python3, and vice versa for the 2nd one. Follow the testing examples above for exact commands.
Windows:
Problem 1: If you are in Windows, and you fail to install the required third party Python libraries, it might print an error similar to: Exception: Error: OpenPose library could not be found. Did you enable BUILD_PYTHON in CMake and have this Python script in the right folder?. From GitHub issue #941:
I had a similar issue with Visual Studio (VS). I am pretty sure that the issue is that while you are compiling OpenPose in VS, it tries to import cv2 (python-opencv) and it fails. So make sure that if you open cmd.exe and run Python, you can actually import cv2 without errors. I could not, but I had cv2 installed in a IPython environment (Anaconda), so I activated that environment, and then ran (change this to adapt it to your VS version and location of OpenPose.sln):
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild.exe
C:\path\to\OpenPose.sln
Problem 2: Python for Openpose needs to be compiled in Release mode for now. This can be done in Visual Studio. Once that is done check this line:
sys.path.append(dir_path + '/../../python/openpose/Release');
dir ../../python/openpose/Release
Check the contents of this location. It should contain one of the following files:
pyopenpose.cp36-win_amd64.pyd
pyopenpose.pyd
If such a folder does not exist, you need to compile in Release mode as seen above. If you have the first one, you have compiled PyOpenPose for Python 3, and have to run the scripts with python3, and vice versa for the 2nd one. Follow the testing examples above for exact commands. If that still does not work, check this line:
os.environ['PATH'] = os.environ['PATH'] + ';' + dir_path + '/../../x64/Release;' + dir_path + '/../../bin;'
dir ../../x64/Release
dir ../../bin
Ensure that both of these paths exist, as PyOpenPose needs to reference those libraries. If they don't exist, change the path so that they point to the correct location in your build folder.
I need to test unity 3d app on mobile device (or emulator). I do not want to press on buttons using coordinates only, so I want to use Sikuli. I will describe steps that I have already done:
Downloaded and installed Sikuli v1.1.1
Installed java 32bit
Installed jython 2.7.0
jython added as interpreter in my project in pyCharm
sikulixapi is run
Copied Sikuli lib from appData to jython folder
Created Python file and added imports
And when I try to run project I receive this error:
D:\jython2.7.0\bin\jython.exe -Dpython.path=D:\python_projects\sikuli_test D:/python_projects/sikuli_test/test_sikuli.py
Tra**ceback (most recent call last):
File "D:/python_projects/sikuli_test/test_sikuli.py", line 1, in <module>
from sikuli import Region
File "D:\jython2.7.0\Lib\sikuli\__init__.py", line 5, in <module>
from org.sikuli.basics import Debug
ImportError: No module named sikuli
Process finished with exit code -1**
What am I doing wrong?
The following works for me:
import org.sikuli.script.SikulixForJython
before
from sikuli import *
In your jython project interpreter, set the environment variables path to where your sikuli jar is placed. That should fix it.
Also make sure to use this in your code
import org.sikuli.script.SikulixForJython
from sikuli import *
I have a code in python that I have been working on and it builds and runs very well on my pc (Windows). I had to run the same code on my other machine which runs ubuntu,so I had to install all the packages on prior to runing the code. The problem is I ran into this error which I couldn't figure out. The error is triggered by one of the installed packages.
from qalsadi import analex
File "/usr/local/lib/python2.7/dist-packages/qalsadi/analex.py", line 14, in <module>
import pyarabic.araby as araby # basic arabic text functions
File "/usr/local/lib/python2.7/dist-packages/pyarabic/araby.py", line 28, in <module>
from stack import *
ImportError: No module named stack
I used the following command, "sudo pip install pyarabic", to install it. However, still the file stack.py doesn't exist among it's files. I searched in the folder /usr/local/lib/python2.7/dist-packages/pyarabic. The folder contains the following: araby.py and init.py and the coresponding pyc files only. I'v insalled and uninstalled it a number of times using "pip" but still the file is not there.
Check your pyarabic folder. Usually it's in Python27\Lib\site-packages\pyarabic.
There, there should be stack.py. If it doesn't exists, re-download pyarabic and then reinstall it.
After installation of pyarabic import STACK in this manner:
from pyarabic.stack import Stack
for window users
open cmd prompt and type the following to install the stack variable to python 3.x-
pip install pyarabic
To install and run with this code-
from pyarabic.stack import Stack
It seems like stack is not part of the Python Package Index so most probably it is a script you installed manually. The problem can be that the folder containing stack.py is not on your PYTHONPATH.
Open a terminal (Ctrl+ Alt + t) and edit the .bashrc file:
sudo gedit ~/.bashrc
Add the following line:
export PYTHONPATH=$PYTHONPATH:/path/to/the/folder/of/your/module
where you should substitute the part after the : to the full path to the directory
where stack.py can be found.
I hope this helps.
I am attempting to bundle up a Python application using py2exe 0.6.9 and Python 2.6.4 on Windows. While the executable runs just fine on the system I used to build it, it fails when I attempt to run it on another system:
C:\Documents and Settings\Administrator\Desktop\dist>.\backend.exe install
Traceback (most recent call last):
File "boot_service.py", line 6, in <module>
File "zipextimporter.pyo", line 82, in load_module
File "win32serviceutil.pyo", line 9, in <module>
File "zipextimporter.pyo", line 98, in load_module
ImportError: MemoryLoadLibrary failed loading win32api.pyd
I have a strong hunch that I'm missing a library, but I'm unsure which—especially since the dependency checker isn't flagging anything as missing on the target system. How should I proceed?
same question as https://stackoverflow.com/questions/1979486/py2exe-win32api-pyc-importerror-dll-load-failed.
look at setup.py, just excludes these dlls which are included in the system.
'dll_excludes': [ "mswsock.dll", "powrprof.dll" ]
it will help you!
You can do the dll and dependency check manually. When you generate the exe i am sure you have noticed that it prints out the dll's that are required/used. Check on the system, where the exe is not working, if the dll's exist and if they are the same version.
One other thing. Are you copying the whole dist folder to the system or just the exe, because you need the whole dist folder and not just the exe.
Are you doing the py2exe conversion on a 64bit/vista?
I've been writing my code on a vista64bit, and the .exe files I create usually do not work on 32bit XP (those are the two machines i have on hand).
The .exe helpfully throws out a text file with the traceback, and it appears that the 64bit windows uses the win32api.dll. I assume this is a .dll used by 64bit windows to replicate 32bit OS behaviour, so I simply take the same script and do the conversion on the 32bit XP. Hope that helps.
Just for anyone who will come to here in the future. If you are using any kind of win32 library and u stuck with this type of errors you can do the following steps:
The problem issue is that there is a conflict between win32 functions dll files and the py2exe automatically dll files. So to solve this conflict you have to know your functions required dll files, then exclude these files from the setup options
Example:
According to the following code:
import win32crypt
win32crypt.CryptUnprotectData(...)
I used the CryptUnprotectData function so I searched for the CryptUnprotectData required dll and I found the following info enter link description here , As u can see,
"Crypt32.dll" is required.
so I edit my setup.py to be look like that
includes = ["win32crypt"]
dll_excludes=["Crypt32.dll"]
setup(
options = {'py2exe': {'bundle_files': 1, 'compressed': True,'dll_excludes': dll_excludes,'includes': includes}})
and it worked perfectly.