I dealt with this issue several posts back where I somehow accidentally "solved" the problem, but predictably it has resurfaced. I need to make my Python script executable just by clicking on it. I have already read the information posted in How to execute Python scripts in Windows?; but I am having an issue wherein scriptA that the user executes with the shortcut calls scriptB which is then unable to import user installed modules. This program works perfectly fine when I execute it like so:
python scriptA.py
But, the combination of calling scriptA by clicking on it and having it call scriptB gives scriptB import errors that do not occur otherwise. Thinking this was a path issue, I tried adding as many possible paths to PATH and PYTHONPATH as they could possibly need, which just gives a different but related import error.
In scriptA I have
from Tkinter import *
from subprocess import call
import numpy
# some code
call(["python", "levMap12.py", inputFilePath, outputFilePath, LVscalingFactor, corrFilePath, corrScalingFactor])
And in scriptB I have
import math
import Levenshtein as LV
import csv
import openpyxl
import sys
import pickle
# some code
File paths:
PATH
C:Python27;C:Python27\Scripts;C:Python27\Lib;C:Python26;C:\Python26\Scripts;C:\Python26\Lib;C:\python-Levenshtein-0.12.0\Levenshtein;C:\Python26\Lib;C:\python-Levenshtein-0.12.0;C:\Program Files\7-Zip\
PYTHONPATH
C:\python-Levenshtein-0.12.0\Levenshtein;C:\python-Levenshtein-0.12.0
Full trackback:
Traceback (most recent call last):
File "levMap12.py", line 3, in <module>
import Levenshtein as LV
File "C:\python-Levenshtein-0.12.0\Levenshtein\__init__.py", line 1, in <module>
from Levenshtein import _levenshtein
ImportError: cannot import name _levenshtein
This error occurs when I simply double click on the scriptA.py file. However, when I try to execute the file by choosing open with python.exe, I get another error
python: can't open file 'levMap12.py': [Errno 2] No such file or directory
I have enabled the setting to use python.exe for all .py files and added .PY to the PATHTEXT system variable
Also, if it is of any relevance, I am using Windows 8 and Python 2.7