Summary of problem:
Using the python interpreter, I type import pyPDF2 and get a ModuleNotFound error even though I have installed the pyPDF2 module:
>>> import pyPDF2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pyPDF2'
What I have tried:
I am using Windows 10. I am new to python. I have installed Python 3.8.3 to a C:\Python38 folder. I have installed pyPDF2 via 'pip install pyPDF2'. The windows path includes the folders: C:\Python38\Scripts\;C:\Python38\.
At the windows Command Prompt I type 'python' and get:
c:\>python
Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:37:02) [MSC v.1924 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
At the python interpreter prompt I type 'import pyPDF2' and get:
>>> import pyPDF2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pyPDF2'
>>>
Note: There is installed an old version of python 2.7 from an ArcGIS install. Could that be causing a conflict? If not, I would rather not uninstall that version since it goes with ArcGIS, which I use.
What I am really trying to do is to automate the concatenation of 7,696 pdf files into 104 pdf files. So far my program looks like this:
import os
from pyPDF2 import PdfFileMerger
source_dir = os.getcwd()
merger = PdfFileMerger()
for item in os.listdir(source_dir):
if item.beginswith('District001_Pg'):
merger.append(item)
merger.write('District001.pdf')
merger.close()
Any help anyone is able to provide will be greatly appreciated!
If you want to run 2 different versions of python in the same machine without having conflicts, you can use VirtualEnv. Here is a document which I found on the web to get you started.
https://www.freecodecamp.org/news/installing-multiple-python-versions-on-windows-using-virtualenv/
Related
When importing requests in python3, I'm getting the following error:
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 32
bit (Intel)] on win32 Type "help", "copyright", "credits" or
"license" for more information
>>>> import requests
Traceback (most recent call last): File "<stdin>", line 1, in <module> File
"C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests-2.19.1-py3.7.egg\requests\__init__.py", line 44, in <module>
import chardet
ModuleNotFoundError: No module named 'chardet'
This is a fresh install, but because of the env I'm working in, I couldn't use pip to install requests. I had to download the source and install via the setup.py install file.
Doing some searches yields some results, but nothing that seems to be a solution for my situation.
Thanks
It is a dependency and is missing from you site-packages. Since you said you can't use pip you have to install the dependencies manually.
requires = [
'chardet>=3.0.2,<3.1.0',
'idna>=2.5,<2.8',
'urllib3>=1.21.1,<1.24',
'certifi>=2017.4.17'
]
this is what requests setup files mentioned as requirements for requests. Try installing all of these and try again.
hope this helps!
Try installing chardet module using this command:
pip3 install chardet
I open cmd.exe in the installed directory and type 'python':
C:\Python34>python
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:43:06) [MSC v.1600 32 bit (In
tel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Basic math works fine:
>>> 4+4
8
I can import, but can't seem to do basic things like check the version, or use pip, etc.:
>>> import os
>>> os.getcwd()
'C:\\Python34'
>>> -version
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'version' is not defined
>>> import pip
>>> pip install flask
File "<stdin>", line 1
pip install flask
^
SyntaxError: invalid syntax
I'm relatively new to this so might be doing something stupid, but I can't figure out what's going on.
Notice the triple chevrons (">>>") means you are inside the Python REPL. Install packages either:
outside Python at the commandline (recommended)
inside Python (less common)
Try the first option:
In cmd
> pip install requests
> python # activates python
In Python
>>> import requests
>>> r = requests.get("https://www.google.com")
>>> r.status_code
200
You cannot do pip install inside the python interpreter. Befor enterig the interpreter, try pip install, if you do not have pip, google for getpip.py.
I've used MSYS2 to install the MinGW-W64 version of Python 3.6 (mingw-w64-x86_64-python3). Upon importing ssl, an ImportError is raised:
$ python3
Python 3.6.2 (default, Aug 15 2017, 10:59:43) [GCC 7.1.0 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "G:/msys64/mingw64/lib/python3.6\ssl.py", line 101, in <module>
import _ssl # if we can't import it, let the error propagate
ImportError: DLL load failed: The specified procedure could not be found.
>>>
I'm not sure why this. pacman shows both mingw-w64-x86_64-openssl and openssl as installed. /mingw64/lib/python3.6/lib-dynload/_ssl-cpython-36m.dll exists. Other .dll files from the same directory (like those used for the json and sqlite3 modules) import fine.
To make matters weirder, the Python 2 version (mingw-w64-x86_64-python2) doesn't have this problem.
This is not a correct solution (the MSYS2 folks are working on the real solution), but as a temporary workaround for anyone else who gets stuck on this:
After installing mingw-w64-x86_64-python3 copy
C:\msys64\mingw64\bin\LIBEAY32.dll and
C:\msys64\mingw64\bin\SSLEAY32.dll
to
C:\msys64\mingw64\lib\python3.6\lib-dynload\LIBEAY32.dll and
C:\msys64\mingw64\lib\python3.6\lib-dynload\SSLEAY32.dll respectively.
Afterwards import ssl (and tools that rely on it, like pip3) should work correctly.
So i wanted to use the Quandl package to learn some data processing. I installed Quandl in the pycharm package, and it worked out pretty well.
import Quandl, math
and then, i use the Quandl to get some data from the internet
data = Quandl.get('some form of data')
But then when i tried to run the python script
bash-3.2$ python Regression.py
Traceback (most recent call last):
File "Regression.py", line 2, in <module>
import Quandl, math
ImportError: No module named Quandl
In my Pycharm interpreter, i have 4 different types:
-2.7.11 (/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/bin/python2.7) I installed Quandl here
-3.5.1 (/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/bin/python3.5) I also installed it here
-2.6.9 (/System/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6) It has an error to install packaging tools
-/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 Permission denied for installing
When i tried to import Quandl in the terminal through python shell, i also retired an error
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import Quandl
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named Quandl
I also tried the same thing for Simple CV, it also says that it's not in the module, even though I've already installed it both in 3.5 and 2.7.
from SimpleCV import Camera
cam = Camera()
while True:
img = cam.getImage()
img = img.binarize()
img.drawText("Hello World")
img.show()
bash-3.2$ python simplecv.py
Traceback (most recent call last):
File "simplecv.py", line 1, in <module>
from SimpleCV import Camera
ImportError: No module named SimpleCV
For installing 'pip', i also had an error installing it in the Pycharm terminal. I've already asked a question about it Installing pip in Pycharm 2016.3
Try to install it using pip2.7. I suspect that you are trying to execute the script with python3 (python command), however, your python interpreter in pyCharm is python2.7.
If you keep getting errors I suggest you to research a bit about virtualenvs, as it can help you had your several dependencies and interpreters easly organized by proyect. (PyCharm has support for virtualenvs)
When you invoke "python" in your console it launches the default Python interpreter (in your case Python 2.7.10). Looks like in PyCharm you selected different interpreter and installed packages on it. Make sure you use the same interpreter in PyCharm (Settings | Project | Project interpreter)
I followed the instructions here...
https://github.com/ahupp/python-magic#dependencies
I ran pip install python-magic and it installed without any issues. Then I installed cygwin and added C:\cygwin\bin to my system path. When I run the python interpreter in a Windows command prompt and import magic I get this error...
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import magic
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\magic.py", line 161, in <module>
raise ImportError('failed to find libmagic. Check your installation')
ImportError: failed to find libmagic. Check your installation
>>>
Did I miss a step?
The python-magic use libmagic,
The libmagic needs magic1.dll,
That magic1.dll is in the file package of gnuwin32.
Solution 1:
Download binaries zip or setup package of file, and adding path of bin directory of it to PATH environment variable.
Solution 2:
Also there is a new change-set in code of python-magic that fixed the problem and you don't need to file package of gnuwin32 (just add bin directory of cygwin to PATH), but currently there is not yet in magic.py while you install it with pip install python-magic or by pip install python-magic --upgrade,
So you need to install python-magic from master.
Also have a look at this post: http://www.thehackeruniversity.com/2014/02/02/obtain-python-mime-types-windows/
This guy uses Hachoir to find the mime info for binary files.