Running Python Script from outside of Python Error: DLL load failed while importing etree: The specified module could not be found - python

So I was using Python IDLE to create my codes, created an environment variable to run the code from run window outside of idle and it was working fine. Recently I downloaded Anaconda for a class and when I try to run a code from outside of idle I get the below message error. Is there a way to change the directory which python is looking for packages to a different path as I assume once I downloaded Anaconda the path has changed. I appreciate you help.
Here is my traceback
File "C:\Users\h.omail\MyPythonScripts\RFQs.py", line 1, in <module>
import os, os.path, docx, win32com.client, shutil, send2trash, PyPDF2, textract, re, pprint
File "C:\Users\h.omail\Anaconda3\lib\site-packages\docx\__init__.py", line 3, in <module>
from docx.api import Document # noqa
ImportError: DLL load failed while importing etree: The specified module could not be found.

pip install python-docx
OR
pip3 install python-docx

Related

ffpyplayer ImportError: DLL load faileld while importing player

I'm working on Windows 10, using python3.8. I wanted to install the ffpyplayer module, and did so using the command:
python3 -m pip install --upgrade ffpyplayer
There seemed to be no issues. Using python in PowerShell and stating import ffpyplayer doesn't return anything, however, when I try and run `from ffpyplayer.player import MediaPlayer. It returns the following error
from ffpyplayer.player import MediaPlayer
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File
"C:\Users\g\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\ffpyplayer\player\__init__.py", line 10, in <module>
from ffpyplayer.player.player import MediaPlayer
ImportError: DLL load failed while importing player: The specified module could not be found.
Why is it able to import in one instance and not the next? What is causing the import error in the second example?
ffpyplayer builds ffmpeg include path as follows:
_ffmpeg = join(sys.prefix, 'share', 'ffpyplayer', 'ffmpeg', 'bin')
sys.prefix resolves to Python installation directory, e.g. C:\Program Files\Python.
If ffpyplayer is installed using PIP not in CMD administrator mode, the package is installed into user local %AppData%\Python directory. This is the reason ffmpeg does not get resolved as expected.
Solution:
pip uninstall ffpyplayer
CMD (Administrator mode)
pip install ffpyplayer
I answered a similar question, but basically import ffpyplayer in your specfile and add ffpyplayer.dep_bins to your tree like so:
*[Tree(p) for p in (source1 + source2 + ffpyplayer.dep_bins)]
https://stackoverflow.com/a/70392062/16355112

pywin32 ImportError: DLL load failed: The specified module could not be found

I'm using python 3.6 and attempting to import win32com.client as win32 to be able to send an email with outlook but keep getting the above import error.
I've installed both pywin32 and pypiwin32 and run the postinstall script (did see it say "You do not have the permissions to install COM objects.)
I see the pywintpyes36.dll and pyhoncom36.dll in the location I'm running the script out of.
I've done a bit of searching and can't seem to find what I'm missing. Is it the fact that I was unable to install the COM objects? Any help would be greatly appreciated, thanks.
[EDIT]
I'm working out of a venv, and have installed both libraries using py -m pip install pywin32 and py -m install pypiwin32. I verified that I see the installation in the "site-packages" folder within my venv.
my imports:
import sys
sys.path.append("C:\path\venv\Lib\site-packages")
import tkinter as tk
import getpass
import os.path
import time
import os
import win32com.client as win32
import sqlite3
from datetime import datetime
from functools import partial
I have the sys.path.append there otherwise the module is not found at all.
Full error message:
Traceback (most recent call last):
File "C:\path\program.py", line 8, in <module>
import win32com.client as win32
File "C:\path\venv\Lib\site-packages\win32com\__init__.py", line 5, in <module>
from win32 import win32api
ImportError: DLL load failed: The specified module could not be found.
This may not be directly relevant for the OP, but may be of help to others who end up here based on the title.
Summary
Possible workaround for conda environments with Python>=3.8:
DO NOT pip install pywin32, but
DO conda install pywin32 (e.g. from conda-forge)
Details
I encountered the following error in a freshly created (Mini-)Conda environment with Python 3.9 on windows 10, after installing pywin32 via pip:
ImportError: DLL load failed while importing win32file: The specified module could not be found.
The pywin32 installation instructions mention this type of issue explicitly, and there are several related issues.
However, in my case something else was going on.
Here are some interesting observations:
I have numerous other, pre-existing, conda environments, with python versions ranging from 2.7 to 3.8, and corresponding pywin32 versions, in which the issue does not arise (just verified this).
All these environments have their own pywintypesXX.dll etc. yet they coexist peacefully.
There is no pywintypesXX.dll in my system32 folder.
I have never needed to run the pywin32_postinstall script, yet.
As it turns out, on my system, the import error only arises if I do a pip install pywin32 in a conda environment with Python>=3.8. The issue does not arise for Python 3.7 (nor for 2.7).
In a Python>=3.8 conda environment, conda install pywin32 fixed the issue (instead of using pip).
Apparently Python 3.8 changed the way dll files are found. This change has been incorporated in pywin32, but can still cause trouble if you mix conda and pip.
Related:
DLL load failed: The specified procedure could not be found. win32api, sys, os
How to fix "ImportError: DLL load failed" while importing win32api
How to fix 'DLL load failed while importing win32api' in Jupyter notebook after connecting VS code to Jupyter notebook?

No module named 'PyPDF2' When Trying to Import

I am attempting to Import PyPDF2 in order to read a PDF file and parse through it. I am using a Raspberry Pi, and have installed PyPDF2 using the command pip install PyPDF2. However, when I try importing it, I am getting ModuleNotFoundError.
I think it may have installed it into the wrong location. When I do python -V it says I am using version 2.7.16. But the error states it's trying to look into the python3 folder?
I am attempting to import it using the line import PyPDF2
The error I'm getting is:
Traceback (most recent call last):
File "/home/pi/SqlDatabase.py", line 5, in <module>
import PyPDF2
File "/usr/lib/python3/dist-packages/thonny/backend.py", line 305, in _custom_import
module = self._original_import(*args, **kw)
ModuleNotFoundError: No module named 'PyPDF2'
Any idea of how I can install PyPDF into the correct directory, or perhaps a different solution?
If you are starting the program with python3 (e.g. see if the first line of the file has #!/usr/bin/python3 or similar), you need to install the library with pip3.
It seems that you have not installed PyPDF2 module in your device.
Execute following code in your terminal:
pip install PyPDF2
or
pip3 install PyPDF2
I think this will solve your problem. If this does not solve your problem, then there may be problem in your directory of python.
I have also faced the same issue. Note that Python is a case-sensitive language.
While using the import command use PyPDF2 and not pyPDF2
To install:
pipenv install PyPDF2
To import:
import PyPDF2

Python - Tweepy Module - pip.req

When I am trying to install tweepy module for python on windows 7, I type in easy_install tweepy
and it gives me the error of:
ImportError: No module named pip.req
I already read the link below but I am a newbie and didnt understand it:
No module named pip.req
PLEASE HELP!!
You should look inside the file setup.py in your folder with downloaded tweepy.
There you could find the line:
from pip.req import parse_requirements
setup.py tries to import parse_requirements function from module req from package pip.
But inside tweepy folder there are no pip package with req.py python module. Read about Python packages and modules here.
So you need to do the steps from the answer https://stackoverflow.com/a/25193001/821093 to fix it.
You can do a simply one line command as suggested by Tweepy installation
Or you can download the file yourself and put on your desktop (or wherever you like). From the windows command type:
cd deskstop\tweepy-master # tweepy-mast is defaul name from the zip download
python steup.py install
You can access the command prompt window using the "Window key" + "R" then type "cmd".

ImportError: No module named 'googlevoice'

python noob here. Just start picking up python few weeks ago and currently need some help. I have 3.3.4 python for windows 7 and I tried running this:
import urllib.request
from googlevoice import Voice
from googlevoice.util import input
import time
File "<pyshell#0>", line 1, in <module>
from googlevoice import Voice
ImportError: No module named 'googlevoice'
so I figured. no big deal, I just need to install the module. I obtained a setup.py file from the link below and ran the file in different directories. Then tried " import googlevoice" but still doesn't work. The github link isn't too helpful, in terms of installing this module. Please help? I think I just have not learned how to install modules properly. Last time it took me a while to install pygame module, but i think it was because of directory issues at first.
https://pygooglevoice.googlecode.com/hg/
http://sphinxdoc.github.io/pygooglevoice/examples.html
To install the PyGoogleVoice, you need to download the whole archive and execute:
python setup.py install
If you have pip install, you can also run pip install pygooglevoice, or easy_install pygooglevoice with EasyInstall, without having to download the source code.

Categories