2017-09-09 1 views
-3

Ich versuche, Python-Skript aus C# -Programm ausführen. Ich verwende offizielle Dokumentation von Microsoft: Inter-process communication between C# and Python. Ich soll dieses Projekt bereitstellen, indem ich es als .exe mache. Wenn ich .exe Datei bin exectuing, es wirft error: 'No module named numpy/ matplotlib.Suggest me some idea to resolve this issue. Proben Datei unten gegeben:Installieren Python App-Abhängigkeit ohne Pip-Installationsbefehl

demo.py

import numpy as np 
from skimage import measure 
import scipy 
import cv2 

'some code using above package' 
+0

@ L.B Frage selbst ist spezifisch, um Paketproblem zu lösen. Nicht mehr als das. – Zara

Antwort

2

Sie Python-Pakete lokal w/o root/admin Berechtigungen installieren. Ich habe den nächsten Code getestet und es funktioniert.

import pip 
import os 
import sys 

def pip_install(packages, dir_to_install): 
    for package in packages: 
     pip.main(['install', '--target={}'.format(dir_to_install), package]) 

local_repo_path = os.path.abspath('local_repo') 
sys.path.append(local_repo_path) 
packages_list = ['numpy', 'scikit-image', 'opencv-python'] 
pip_install(packages_list, local_repo_path) 

import numpy as np 
from skimage import measure 
import scipy 

'some code using above package' 
+0

Ihre Antwort ist sehr hilfreich für mich. Aber ich habe noch eine Frage, wie wird Ihr Code für Windows-Umgebung funktionieren. Becuase System kann 32 Bit/64 Bit sein. Pakete sollten entsprechend heruntergeladen werden. Wie kann ich im selben Code opencv2.7 version/opencv3.2 installieren? – Zara

+0

Ich bin nicht vertraut mit "Windows OS", aber ich nehme an, dass Pip Crossplatform-Tool ist und ich glaube, dass das Verhalten das gleiche ist. Um Paket-Version zu wählen, können Sie als nächstes 'pip install opencv-python == 2.7' – RedEyed

+0

Ich habe dies nicht überprüft. Fügen Sie also 'opencv-python == 2.7' und' opencv-python == 3' zur 'packages_list' hinzu. Beachten Sie auch, dass diese Version anders sein kann, überprüfen Sie es bitte. – RedEyed

Verwandte Themen