I successfully installed the module geocoder:
Requirement already satisfied: chardet<5,>=3.0.2 in
c:\users\myname\appdata\roaming\python\python39\site-packages (from
requests->geocoder) (4.0.0) Installing collected packages: ratelim,
geocoder Successfully installed geocoder-1.38.1 ratelim-0.1.6
When I try to create a Python file that includes import geocoder, I get the error Import "geocoder" could not be resolved.
The relevant path is included in sys.path:
C:\Users\myname\Downloads
C:\Users\myname\AppData\Local\Programs\Python\Python39\python39.zip
C:\Users\myname\AppData\Local\Programs\Python\Python39\DLLs
C:\Users\myname\AppData\Local\Programs\Python\Python39\lib
C:\Users\myname\AppData\Local\Programs\Python\Python39
C:\Users\myname\AppData\Roaming\Python\Python39\site-packages
C:\Users\myname\AppData\Roaming\Python\Python39\site-packages\win32
C:\Users\myname\AppData\Roaming\Python\Python39\site-packages\win32\lib
C:\Users\myname\AppData\Roaming\Python\Python39\site-packages\Pythonwin
C:\Users\myname\AppData\Local\Programs\Python\Python39\lib\site-packages
C:\Users\myname\AppData\Local\Programs\Python\Python39\lib\site-packages\win32
C:\Users\myname\AppData\Local\Programs\Python\Python39\lib\site-packages\win32\lib
C:\Users\myname\AppData\Local\Programs\Python\Python39\lib\site-packages\Pythonwin
Why isn't Python able to resolve this module?
Thanks
Either geocoder is installed to other than Python3.9 version installation (e.g. python 3.7) or geocoder is not in the path of your python module.
Try to install the library using specific Python pip package manager (e.g. pip3.9) and run the module you develop using specific Python version (e.g. Python3.9)
Note: This is not an issue with Visual Studio, but rather with incompatible dll versions. The steps below replicate the problem since running in Visual Studio in debug mode breaks on exceptions being thrown. If you just run, the thrown exception is handled elsewhere and the program works fine. But since I spend a lot of time in debug mode, I would prefer to fix this problem.
When debugging, I want to be able to step into modules I have added to my Virtual Environment in Visual Studio. I get a 'library not found' error that I am not able to fix. Here are the steps:
In Visual Studio create a new Python Application.
Create a virtual environment for that application (Python 3.6 64
bit).
pip install twilio into your virtual environment. You get the
following output.
...
----- Installing 'twilio' -----
Collecting twilio
Using cached twilio-6.10.5-py2.py3-none-any.whl
Collecting pytz (from twilio)
Using cached pytz-2018.3-py2.py3-none-any.whl
Collecting six (from twilio)
Using cached six-1.11.0-py2.py3-none-any.whl
Collecting PyJWT>=1.4.2 (from twilio)
Using cached PyJWT-1.6.0-py2.py3-none-any.whl
Collecting requests>=2.0.0; python_version >= "3.0" (from twilio)
Using cached requests-2.18.4-py2.py3-none-any.whl
Collecting pysocks; python_version >= "3.0" (from twilio)
Using cached PySocks-1.6.8.tar.gz
Collecting certifi>=2017.4.17 (from requests>=2.0.0; python_version >= "3.0"->twilio)
Using cached certifi-2018.1.18-py2.py3-none-any.whl
Collecting chardet<3.1.0,>=3.0.2 (from requests>=2.0.0; python_version >= "3.0"->twilio)
Using cached chardet-3.0.4-py2.py3-none-any.whl
Collecting urllib3<1.23,>=1.21.1 (from requests>=2.0.0; python_version >= "3.0"->twilio)
Using cached urllib3-1.22-py2.py3-none-any.whl
Collecting idna<2.7,>=2.5 (from requests>=2.0.0; python_version >= "3.0"->twilio)
Using cached idna-2.6-py2.py3-none-any.whl
Installing collected packages: pytz, six, PyJWT, certifi, chardet, urllib3, idna, requests, pysocks, twilio
Running setup.py install for pysocks: started
Running setup.py install for pysocks: finished with status 'done'
Successfully installed PyJWT-1.6.0 certifi-2018.1.18 chardet-3.0.4 idna-2.6 pysocks-1.6.8 pytz-2018.3 requests-2.18.4 six-1.11.0 twilio-6.10.5 urllib3-1.22
----- Successfully installed 'twilio' -----
Add the following line to the top of your .py file:
from twilio.rest import Client
In Visual Studio go to tools > options > python > debugging. Make
sure 'Enable debugging of Python standard library' is checked
Run the application. You get the following error:
ModuleNotFoundError: No module named 'OpenSSL'
pip install pyopenssl You get the following output:
...
----- Installing 'pyopenssl' -----
Collecting pyopenssl
Using cached pyOpenSSL-17.5.0-py2.py3-none-any.whl
Requirement already satisfied: six>=1.5.2 in c:\users\x\source\repos\pythonapplication9\pythonapplication9\env\lib\site-packages (from pyopenssl)
Collecting cryptography>=2.1.4 (from pyopenssl)
Using cached cryptography-2.1.4-cp36-cp36m-win_amd64.whl
Requirement already satisfied: idna>=2.1 in c:\users\x\source\repos\pythonapplication9\pythonapplication9\env\lib\site-packages (from cryptography>=2.1.4->pyopenssl)
Collecting cffi>=1.7; platform_python_implementation != "PyPy" (from cryptography>=2.1.4->pyopenssl)
Using cached cffi-1.11.5-cp36-cp36m-win_amd64.whl
Collecting asn1crypto>=0.21.0 (from cryptography>=2.1.4->pyopenssl)
Using cached asn1crypto-0.24.0-py2.py3-none-any.whl
Collecting pycparser (from cffi>=1.7; platform_python_implementation != "PyPy"->cryptography>=2.1.4->pyopenssl)
Using cached pycparser-2.18.tar.gz
Installing collected packages: pycparser, cffi, asn1crypto, cryptography, pyopenssl
Running setup.py install for pycparser: started
Running setup.py install for pycparser: finished with status 'done'
Successfully installed asn1crypto-0.24.0 cffi-1.11.5 cryptography-2.1.4 pycparser-2.18 pyopenssl-17.5.0
----- Successfully installed 'pyopenssl' -----
Run the application. You get the following error:
asn1crypto._ffi.LibraryNotFoundError: The library libcrypto could not be found
The error is thrown in the file named _big_num_ctypes.py in asn1crypto. The code line where this is thrown is:
libcrypto_path = find_library(b'crypto' if sys.version_info < (3,) else 'crypto')
if not libcrypto_path:
raise LibraryNotFoundError('The library libcrypto could not be found')
Update: I was asked to provide the full backtrace. I modified the code in this way to print it:
import unittest
import traceback
class Test_test1(unittest.TestCase):
def test_A(self):
try:
from twilio.rest import Client
except Exception as e:
print('foo')
foo = traceback.extract_stack()
traceback.print_exc(e)
if __name__ == '__main__':
unittest.main()
As before the import line throws the exception but the exception is not caught and the lines in 'except' clause are never executed
from twilio.rest import Client
update 2: I somehow had gotten this to work following #Prateek and #user8212173. But now it is not working again. As both suggested, the problem is that crypto.dll is not there. So I went thru the steps below to add it with no success:
I installed Win64 OpenSSL v1.1.0j from https://slproweb.com/products/Win32OpenSSL.html (pointed to from https://wiki.openssl.org/index.php/Binaries). It does not contain crypto.dll.
I then installed crypto.dll from http://www.dlldownloader.com/crypto-dll/ (as #user8212173 suggested) (there is only a 32 bit version) and followed the instructions. I then got a new error message "ImportError: DLL load failed: %1 is not a valid Win32 application" which means that the crypto.dll I installed has a version conflict (I am running 64bit python on a 64bit computer). I remember installing it from Unofficial Windows Binaries for Python Extension Packages I can't find it there. So where do I get a working 64bit version of crypto.dll?
I searched a lot and could find that you are missing crypto.dll file. Your code is looking for this dll file and it is unable to find it.
Please note this wont be installed by pip install crypto as this is python library and the code is looking for a dll file.
ctypes.util.find_library searches for dll file from windows environment path variable.
Reference : find_library() in ctypes
To verify I checked.
find_library('l2gpstore')
>>'C:\\WINDOWS\\system32\\l2gpstore.dll'
find_library('java')
>>'C:\\Program Files\\Java\\jdk-9.0.4\\bin\\java.dll'
Furthermore you should install OpenSSL with libcrypto module from here
OpenSSL
OpenSSL installation instructions
The master sources are maintained in our git repository, which is
accessible over the network and cloned on GitHub, at
https://github.com/openssl/openssl. Bugs and pull patches (issues and
pull requests) should be file on the GitHub repo. Please familiarize
yourself with the license.
libcrypto with respect to OpenSSL
reference : GitHub
libcrypto (with platform specific naming):
Provides general cryptographic and X.509 support needed by SSL/TLS but
not logically part of it.
Once you install binaries and check crypto.dll is available in one of the path strings in your environment variables this issue should be resolved.
If not add it into path variable and check.
Update:
Update since the question has been updated and the issue has recurred.
There are architectural changes with OpenSSL 1.1.0 as compared to 1.0.2
September 13, 2018 - OpenSSL 1.1.0 and later are quite different from previous releases. Users should install BOTH the 1.0.2 series (LTS) and the 1.1.1 (LTS) series for maximum application compatibility. Developers need to recompile their software to support 1.1.1. See the official OpenSSL release strategy document for more details. – Prateek yesterday
If you open 1.0.2 from Github you can see crypto.h file , the same file is missing in latest version. Also OpenSSL there is change in DLL names , they renamed libeay32 to libcrypto
You need to post code which makes use of asn1crypto library in the post. There is no code that explicitly uses asn1crypto in your post. So, not able to reproduce your issue using pipenv.
Make sure you are using updated libraries too.
I would not recommend downloading DLL source from unreliable source like DLLdownloader
If you are having issues with latest version of OpenSSL and asn1crypto its better to downgrade OpenSSL to 1.0.2 ,I think that would work considering it ships with crypto.h file.
Good luck!
I tried to reproduce the error on my computer and was successful when I ran the "error-producing" file _big_num_ctypes.py. Although, I do not have Visual Studio, the error stems from the missing crypto.dll file. We will deduce this step-by-step. Let's first examine the error causing code snippet in the file _big_num_ctypes.py:
#imports
from ctypes.util import find_library
.
.
from .._ffi import LibraryNotFoundError, FFIEngineError
try:
# On Python 2, the unicode string here may raise a UnicodeDecodeError as it
# tries to join a bytestring path to the unicode name "crypto"
libcrypto_path = find_library(b'crypto' if sys.version_info < (3,) else 'crypto')
if not libcrypto_path:
raise LibraryNotFoundError('The library libcrypto could not be found')
.
.
except (AttributeError):
raise FFIEngineError('Error initializing ctypes')
I ran the file:
C:\>cd "C:\ProgramData\Anaconda3\Lib\site-packages\asn1crypto\_perf"
C:\ProgramData\Anaconda3\Lib\site-packages\asn1crypto\_perf>python _big_num_ctypes.py
and had a Traceback for the library import:
Traceback (most recent call last):
File "_big_num_ctypes.py", line 27, in <module>
from .._ffi import LibraryNotFoundError, FFIEngineError
ValueError: attempted relative import beyond top-level package
So, I changed the import path for.ffito:
from asn1crypto._ffi import LibraryNotFoundError, FFIEngineError
On the second run, the missing libcrypto library error appeared:
asn1crypto._ffi.LibraryNotFoundError: The library libcrypto could not be found
The exception is raised when the dll library named crypto could not be found at C:\Windows\System32 and/or SYSWOW64(for 64-bit)
libcrypto_path = find_library(b'crypto' if sys.version_info < (3,) else 'crypto')
The purpose of find_library is to find a specified library and return a pathname. The behavior of this method varies with OS as described in the docs. If this method cannot find any packages, it returns None.
>>> from ctypes.util import find_library
>>> print(find_library("c"))
None
In our case, the search is for crypto.dll and I couldn't find this file on my computer. So, I downloaded and installed it exactly according to the instructions here. When I checked again:
>>> find_library('crypto')
'C:\\windows\\system32\\crypto.dll'
Now I ran python _big_num_ctypes.py again and got a different Traceback:
Traceback (most recent call last):
File "_big_num_ctypes.py", line 37, in <module>
libcrypto = CDLL(libcrypto_path)
File "C:\ProgramData\Anaconda3\lib\ctypes\__init__.py", line 348, in __init__
self._handle = _dlopen(self._name, mode)
OSError: [WinError 193] %1 is not a valid Win32 application
A further investigation into the above error revealed that if I'm using a 32bit DLL with 64bit Python, or vice-versa, then I may get such errors as explained here. So, I installed Python 3.6 32-bit and tried again with py -3.6-32 _big_num_ctypes.py. I also installed all the required packages, but this error persisted.
Could it be possible that we may require 32-bit binaries for the Crypto package? This answer and this give more information.
I realized that Pycryptodome is a regularly maintained package and is preferred over the old Crypto package but can still be installed under Crypto. Another point to notice is that one of the requirements for this package is MS Visual Studio 2015 (Community Edition) and the C/C++ compilers and the redistributable only. It could be possible that some C++ compiler files or MS Visual Studio files are missing at present and causing these issues to happen.
If you install all the above prerequisites, the crypto.dll file and the Pycryptodomepackage, I believe this error will be Resolved. You have already installed other required packages OpenSSL & Twilio. Unfortunately, I am restricted to install MS Visual Studio on my computer and so I couldn't test this further.
I also ran the unittest code and it ran successfully for me:
#Output
.
----------------------------------------------------------------------
Ran 1 test in 0.771s
OK
Here is my solution for windows 10, visual studio community 2017,
open file C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\Lib\site-packages\asn1crypto_perf_big_num_ctypes.py and then change the code from :
libcrypto_path = find_library(b'crypto' if sys.version_info < (3,) else 'crypto')
to:
libcrypto_path = find_library(b'crypto' if sys.version_info < (3,) else 'libcrypto')
then the error msg is gone.
The libcrypto.dll is already under folder C:\Windows\System32\
I'm trying to use Python with the Twisted framework, and have been struggling to get it running.
I've got some dirt simple python code:
from twisted.internet import reactor
reactor.run()
Buy when I run python server.py I get back:
File "server.py", line 1, in <module>
from twisted.internet import reactor File "/Library/Python/2.7/site-packages/twisted/__init__.py", line 53, in
<module>
_checkRequirements() File "/Library/Python/2.7/site-packages/twisted/__init__.py", line 37, in
_checkRequirements
raise ImportError(required + ": no module named zope.interface.") ImportError: Twisted requires zope.interface 3.6.0 or later: no module
named zope.interface.
My first assumption was to run pip install zope.interface
Unfortunately, all I get from this is:
Requirement already satisfied (use --upgrade to upgrade):
zope.interface in
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
Requirement already satisfied (use --upgrade to upgrade): setuptools
in
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
(from zope.interface)
I also tried easy_install zope.interface
But that yields similar results:
Searching for zope.interface
Best match: zope.interface 4.1.1
zope.interface 4.1.1 is already the active version in easy-install.pth
Using /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
Processing dependencies for zope.interface
Finished processing dependencies for zope.interface
Since apparently zope is installed on my machine, I'm thinking that the problem could possibly be with the python I've got installed. I installed Python3 with brew earlier this year, and I think I may have messed up the python configuration. Any ideas?
Update
The default python that is on mac should work for everything I was trying to do above, I verified this on another mac computer. The problem I was having was that I had corrupted my default python image that came with my mac. By following the post below I was able to create working virtualenv again for my python.
You should do all of your Python work in a virtualenv. If you were to make a fresh virtualenv for your Twisted development, and always activate it before working on it, you would have much tighter control over what gets installed and it would be a lot easier to diagnose problems. So please make a new virtualenv and pip install twisted in it, and then this problem should go away.
I have installed pyOpenSSL and all the required packages but i can't import OpenSSL in the shell . I get this error :
>>> import OpenSSL
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named OpenSSL
list of required packages that are allready installed:
cryptography (0.9.3)
distribute (0.7.3)
idna (2.0)
pip (7.1.0)
pyasn1 (0.1.8)
pyasn1-modules (0.0.5)
pyopenssl (0.15.1)
requests (2.7.0)
service-identity (14.0.0)
setuptools (18.1)
six (1.9.0)
Twisted (15.2.1)
urllib3 (1.11)
w3lib (1.12.0)
zope.interface (4.1.2)
If you are running a 64-bit version of Windows then I recommend you install a Win64 version of OpenSSL, available from https://slproweb.com/products/Win32OpenSSL.html (scroll down until you find the 64 bit installers) and the 64-bit version of pyOpenSSL, available from http://www.egenix.com/products/python/pyOpenSSL/
Check that you don't have 32-bit versions of the various products, python-packages, etc. I had some site-packages on the PYTHONPATH which confused python. I removed the environment variable PYTHONPATH and similarly PYTHONUSERBASE (both were recommended by some software I was trying where they wanted to use 32-bit versions of mitmproxy and working backwards everything else...) I want to retain my 64-bit version of Python (2.7.6) hence my struggles as I ran into the same error you reported here.
im using pip requirements file for the dependencies with virtualenv. im using ubuntu10.04LTS now the problem has come up with djangorestframework, after adding it in .pip file
while downloading the requirements #URLObject error occurs and says
Downloading/unpacking URLObject>=0.6.0 (from djangorestframework->-r /var/lib/myproj/base.pip (line 26))
Using download cache from /usr/local/pipcache/http%3A%2F%2Fpypi.python.org%2Fpackages%2Fsource%2FU%2FURLObject%2FURLObject-2.0.1.tar.gz
Running setup.py egg_info for package URLObject
The required version of distribute (>=0.6.24) is not available,
and can't be installed while this script is running. Please
install a more recent version first, using
'easy_install -U distribute'.
(Currently using distribute 0.6.10 (/var/lib/myproj/.ve/lib/python2.6/site-packages/distribute-0.6.10-py2.6.egg))
Complete output from command python setup.py egg_info:
The required version of distribute (>=0.6.24) is not available,
and can't be installed while this script is running. Please
install a more recent version first, using
'easy_install -U distribute'
(Currently using distribute 0.6.10 (/var/lib/myproj/.ve/lib/python2.6/site-packages/distribute-0.6.10-py2.6.egg))
my pip requirement file is as follows:
virtualenv
django
distribute
django-permissions
django-storages
django-sentry
#django-db-utils
PIL
#Required for APIs
djangorestframework
i have even tried by adding distribute-0.6.25 but in vain how do i upgrade distribute via pip requirements file.
I just hit the same issue.
Solved by running:
pip install -U distribute==0.6.25
I don't think you can update it via the requirements file because requirements are installed at once and not one by one.
if you need distribute to be 0.6.25 version, just specify it in the requirements:
virtualenv
django
distribute==0.6.25
django-permissions
django-storages
django-sentry
#django-db-utils
PIL
#Required for APIs
djangorestframework