I tried to build a standalone executable with PyInstaller for Python 3.5 using OpenVino 2020.4.287.
PyInstaller assembled a file successfully but I received the next error after launch:
ImportError: No module named 'openvino'
I tried to include /opt/intel/openvino/deployment_tools/inference_engine/lib/armv7l/plugins.xml in data while building executable but it didn't help.
So the question is how to build a standalone executable in Raspbian with PyInstaller with OpenVino import?
Thanks.
Okay, the issue was resolved.
Initial conditions:
Raspbian Stretch with Python 3.5.
Considerations:
The last OpenVino supporting Python 3.5 is 2020.4.
So, let’s start. We will create a test.py file with the next lines:
import numpy as np
import openvino.inference_engine.constants
from openvino.inference_engine import IENetwork, IECore
print("start")
e = IECore()
print("end")
Now let's install OpenVino, Pyinstaller, create an executable, and run it:
sudo pip3 install pyinstaller
sudo mkdir -p /opt/intel/openvino
wget https://storage.openvinotoolkit.org/repositories/openvino/packages/2020.4/l_openvino_toolkit_runtime_raspbian_p_2020.4.287.tgz
sudo tar -xf l_openvino_toolkit_runtime_raspbian_p_2020.4.287.tgz --strip 1 -C /opt/intel/openvino
rm l_openvino_toolkit_runtime_raspbian_p_2020.4.287.tgz
sudo apt install cmake
source /opt/intel/openvino/bin/setupvars.sh
sh /opt/intel/openvino/install_dependencies/install_NCS_udev_rules.sh
pyinstaller --onefile --clean --add-data="/opt/intel/openvino/deployment_tools/inference_engine/lib/armv7l/plugins.xml:." test.py
dist/test
"start" and "end" messages should be shown.
The most important when you are using OpenVino 2020.4 is the next line:
import openvino.inference_engine.constants
In previous versions of OpenVino everything will work normally without this line. But in my specific case I’ve got the next error on OpenVino versions earlier 2020.4:
openvino.inference_engine.ie_api.IECore' object has no attribute 'read_network
That’s why I specified import for openvino.inference_engine.constants. Without this nothing works in OpenVino 2020.4.
Thanks.
The biggest possibility is you didn't run the setupvars before that implementation.
Please note that you need to ensure the setupvars had been run and initialized(you should see the init message) in each cmd or terminal before proceeding to any further inferencing/etc.
This setupvars would keep the required packages together. Hence, if you didn't run it, the problem like what you are facing would persist.
Related
I'm trying to install Anaconda distribution on Windows docker based nano-server.
This is my dockerfile (based on 4 yeras old example I found in GitHub)
# escape= `
# Use the latest Windows Server Core 2022 image.
FROM mcr.microsoft.com/windows/servercore:ltsc2022 AS base
RUN powershell (New-Object System.Net.WebClient).DownloadFile('https://repo.anaconda.com/archive/Anaconda3-2022.05-Windows-x86_64.exe', 'Anaconda3.exe')
RUN powershell Unblock-File -Path Anaconda3.exe
RUN Anaconda3.exe /InstallationType=JustMe /RegisterPython=1 /S /D=C:\Python
FROM mcr.microsoft.com/windows/nanoserver:ltsc2022-amd64
COPY --from=base C:\Python C:\Python
ENV PATH="C:\Python;C:\Python\Library\mingw-w64\bin;C:\Python\Library\usr\bin;C:\Python\Library\bin;C:\Python\Scripts;C:\Python\bin;C:\Python\condabin;C:\Windows;C:\Windows\System32;"
CMD ["cmd"]
The docker looks ok, I can launch Python, but once I try to import numpy or sklearn I got errors (fail to load some DLLs). I could make numpy work by reinstalling it (pip install --force-reinstall numpy), but this workaround didn't work for other libraries.
I also tried to install only Miniconda, then use conda install to add libraries, but trying to run conda in the nanoserver fails (pythoncom error: coinitializeex failed).
Trying a similar docker but on top of server core (servercore:ltsc2022) works flawlessly.
The reason I struggle to use Anaconda on nanoserver is to minimize its size - the docker size of the container based on servercore adds ~7GB to the size on the nanoserver.
Is it possible to run Anaconda on nano-server?
thanks,
Adi
I am using macOS 10.15.7.
I use pyenv to install Python 3.8.6.
I use python -m venv myenv to setup a virtual environment and activate that environment.
I clone the liblist repo from https://github.com/libimobiledevice/libplist. I then use ./autogen.sh --prefix=/Users/jamesh/tmp/local --enable-debug to generate the Makefile. After make'ing and installing, I get the plist.so file.
$ pwd
/Users/jamesh/tmp/local/lib/python3.8/site-packages
$ ls
plist.a plist.la* plist.so*
I can cd into /Users/jamesh/tmp/local/lib/python3.8/site-packages, run ipython, and execute import plist. As it is importing, it crashes with 'ipython' terminated by signal SIGSEGV (Address boundary error)
I also tried a simple script with:
import sys
sys.path.append( "/Users/jamesh/tmp/local/lib/python3.8/site-packages" )
import plist
with the same result.
I figure I must be doing something wrong and cannot use the plist.so file directly.
What step am I missing?
However, I can do the basically the same on Ubuntu 18.04 and it works.
Trying to make use of this package: https://github.com/microsoft/Simplify-Docx
Can someone pls tell me the proper sequence of actions needed to install and use the package?
What I've tried (as a separate commands from vscode terminal):
pip install python-docx
Git clone <git link>
python setup.py install
After the installation has been successfully completed I'm trying to run from VS Code terminal the file in which I've pasted the code from readme's "usage" section:
import docx
from simplify_docx import simplify
# read in a document
my_doc = docx.Document("docxinaprojectfolder.docx") //I wonder how should I properly specify the path to file?
# coerce to JSON using the standard options
my_doc_as_json = simplify(my_doc)
# or with non-standard options
my_doc_as_json = simplify(my_doc,{"remove-leading-white-space":False})
And I only get
ModuleNotFoundError: No module named 'docx'
But I've installed this module in the first place.
What am I doing wrong? Am I missing some of the steps? (Like init or smth).
Vscode status bar at the bottom left says that I'm using python 3.8.x, and I'm trying to run the script via "play" button.
python --version
Python 3.6.5
py show's though that 3.8.x is being used.
Thanks
Amin sama was right - that was indeed an environment issue.
Looks like modules were getting globally installed in an older python folder. Different from the python which runs when you try to run python file. So I had to uninstall the older python.
After that
py --version
and
Python --version
Started to show the same version unlike before.
So, the sequence
1. Opened a fresh folder within VS Code
2. git clone <git link to repository from github>
3. copied all the files from cloned repo to my current folder (or you can go one level down with cd command)
4. installed dependency: pip install python-docx
5. run setup.py from where you copied files: python setup.py install
6. Copy "usage" into a new file, for example run.py
7. Specify an absolute path to your file with double backslash.
8. Add strings to run.py to output the result in a json:
import json
with open('data.txt', 'w') as f:
json.dump(my_doc_as_json, f, ensure_ascii=False)
Run this file from the terminal opened in your project folder typing run.py or python run.py
It wasn't necessary to open >>> python console.
The problem is that your system doesn't have "docx" module.
to install docx module you will have to install docx.
steps to install:
1) open CMD prompt.
2) type "pip install docx"
if your installation is fresh it may need "simplify" module too.
Like any python package that doesn't come with python, you need to install it before using it. In your terminal window you can install if from the Python package index like this:
pip install simplify-docx
or you can install it directly from GitHub like this:
pip install git+git://github.com/microsoft/Simplify-Docx.git
I have Python on my school computer, but I would like to install a few modules. How could I get passed this problem.
You can try the following:
import subprocess
subprocess.call('pip install X --target=d:\some\folder\with\write\permission', shell=True)
Is a python script that will try to install the package X in some folder that you want. Maybe this way you can do it.
I installed python packages in school with this.
open a python shell and write the following:
import pip
pip._internal.main(["install", "--user", <PACKAGE>])
For school computers that don't allow you install libraries via cmd here's a way around it!
import pip
press enter
pip.main(["install", "--user", "Libraryname"])
"user" may not be important so only use it if it doesn't work the first time running it
I got around this problem by running the following:
import os
os.system('pip install --user X')
which did not require admin privileges.
You may then need to add the packages directory to the path
You can also install libraries from powershell if using a windows computer.
First open up IDLE
import subprocess
subprocess.call('powershell.exe')
After powershell opens it automatically opens to the python directory. You want to go back to C: with cd... From there use cd users and cd yourusername. It should look like.
PS C:/users/your username>
Set environment with
$env:path="$env:Path;c:/path/to/python/folder"
After this you can do a standard pip install.
python -m pip install <pythonlibrary>
Above Error comes only when i am trying to run the script : "rgarg:pytutorial raghav$ python tflearn11.py"
It working fine in Rodeo IDE, also if I put "import tflearn " in command line python interpreter it works fine (even I typed full script in command line , it worked fine w/o import issue) .
My packages are in same location as i have given in my bash (Mac OS El Captain)
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages
A similar problem i found Link but not getting how can i remove path(0) when running from python interpreter.
Thanks
As #Two-Bit mentioned i used virtualenvs Link.
But please make sure use below for installation of virtualenvs
$ sudo easy_install virtualenvs
instead of pip install virtualenvs.