I guess I have a very simple problem, but actually stuck in getting out where exactly the problem is.
My task is to runs a Python script from the Total Commander (TC) command line with a file name as argument.
I use Python 3.7.4. Anaconda is linked in my environmental variables and *.py files are linked in TC:
The test code is:
from docx import Document
from sys import argv
inputfilename = argv[1]
document = Document()
document.save(str(inputfilename) + '_test.docx')
Following error message occurs:
n:\TECHNOLOGY\Products\00_00_ALL_Product\Lasten\_Parafix\3.XM-NES\8.20_Euros\_De
finition_Validierung_Tower>test.py test
Traceback (most recent call last):
File "N:\TECHNOLOGY\Products\00_00_ALL_Product\Lasten\_Parafix\3.XM-NES\8.20_E
uros\_Definition_Validierung_Tower\Test.py", line 8, in <module>
from docx import Document
File "C:\Users\klaus.sandel\AppData\Local\Continuum\anaconda3\lib\site-package
s\docx\__init__.py", line 3, in <module>
from docx.api import Document # noqa
File "C:\Users\klaus.sandel\AppData\Local\Continuum\anaconda3\lib\site-package
s\docx\api.py", line 14, in <module>
from docx.package import Package
File "C:\Users\klaus.sandel\AppData\Local\Continuum\anaconda3\lib\site-package
s\docx\package.py", line 9, in <module>
from docx.opc.package import OpcPackage
File "C:\Users\klaus.sandel\AppData\Local\Continuum\anaconda3\lib\site-package
s\docx\opc\package.py", line 9, in <module>
from docx.opc.part import PartFactory
File "C:\Users\klaus.sandel\AppData\Local\Continuum\anaconda3\lib\site-package
s\docx\opc\part.py", line 12, in <module>
from .oxml import serialize_part_xml
File "C:\Users\klaus.sandel\AppData\Local\Continuum\anaconda3\lib\site-package
s\docx\opc\oxml.py", line 12, in <module>
from lxml import etree
ImportError: DLL load failed: Das angegebene Modul wurde nicht gefunden.
Indeed there is no file such oxml.py in the mentioned folder.
Nevertheless, when I run the code without argument in Spyder:
from docx import Document
from sys import argv
#inputfilename = argv[1]
inputfilename = "TEST"
document = Document()
document.save(str(inputfilename) + '_test.docx')
The document "TEST_test.docx" is created, so I doupt the failure is a missing DLL.
My suspision was that Spyder uses another environment as the comand shell (unfortunately I had several environments). So I deleted all environments, except the base environment, by help of Anaconda Navigator. So I only have the base environment left. The code works without arguments from Spyder, but not with Arguments from TC command line.
Another strange thing that I don't understand is when I call Python.exe from the TC command line:
Python 3.7.4 (default, Aug 9 2019, 18:34:13) [MSC v.1915 64 bit (AMD64)] :: Ana
conda, Inc. on win32
Warning:
This Python interpreter is in a conda environment, but the environment has
not been activated. Libraries may fail to load. To activate this environment
please see https://conda.io/activation
When I call 'python.exe' from Anaconda Prompt everything seems to be alright:
(base) C:\>python.exe
Python 3.7.4 (default, Aug 9 2019, 18:34:13) [MSC v.1915 64 bit (AMD64)] :: Ana
conda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
When I can activate base environment from Cmd shell (started from TC) and call the script in the command shell it somehow works, but not as expected (I added 'print(argv)' in the code):
(base) n:\TECHNOLOGY\Products\00_00_ALL_Product\Lasten\_Parafix\3.XM-NES\8.20_Eu
ros\_Definition_Validierung_Tower>Test.py TEST2
['N:\\TECHNOLOGY\\Products\\00_00_ALL_Product\\Lasten\\_Parafix\\3.XM-NES\\8.20_
Euros\\_Definition_Validierung_Tower\\Test.py']
It seems that only the first argument (the script itself) is found. But not "TEST2".
Nevertheless, from the TC command line the reply is still the same: oxml.py DLL not found...
Has anyone an idea how I get TC to start python in the right environment and to read my arguments? Thousand thanks in advance!
Please let me now, if you need more information!
BR Klaus