Python 3.7.2 ModuleNotFoundError: No module named pysqlite2 - python

I'm working on windows with python 3.7.2 and using uszipcode library and import SearchEngine for getting a list of zip codes which start with the argument of the function.
I'm getting the following errors:
Traceback (most recent call last):
File "C:\Users\user\Anaconda3\lib\site-packages\sqlalchemy\dialects\sqlite\pysqlite.py", line 338, in dbapi
from pysqlite2 import dbapi2 as sqlite
ModuleNotFoundError: No module named 'pysqlite2'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/user/PycharmProjects/tutorial/tutorial/Zillow/zillow_runfile.py", line 38, in <module>
st = zl.zipcodes_list(st_items=["100", "770"])
File "C:\Users\user\PycharmProjects\tutorial\tutorial\Zillow\zillow_functions.py", line 32, in zipcodes_list
search = SearchEngine()
File "C:\Users\user\Anaconda3\lib\site-packages\uszipcode\search.py", line 82, in __init__
engine = connect_to_simple_zipcode_db()
File "C:\Users\user\Anaconda3\lib\site-packages\uszipcode\db.py", line 49, in connect_to_simple_zipcode_db
return engine_creator.create_sqlite(path=simple_db_file_path.abspath)
File "C:\Users\user\Anaconda3\lib\site-packages\uszipcode\pkg\sqlalchemy_mate\engine_creator.py", line 51, in create_sqlite
return create_engine(_create_sqlite(path), **kwargs)
File "C:\Users\user\Anaconda3\lib\site-packages\sqlalchemy\engine\__init__.py", line 423, in create_engine
return strategy.create(*args, **kwargs)
File "C:\Users\user\Anaconda3\lib\site-packages\sqlalchemy\engine\strategies.py", line 87, in create
dbapi = dialect_cls.dbapi(**dbapi_args)
File "C:\Users\user\Anaconda3\lib\site-packages\sqlalchemy\dialects\sqlite\pysqlite.py", line 343, in dbapi
raise e
File "C:\Users\user\Anaconda3\lib\site-packages\sqlalchemy\dialects\sqlite\pysqlite.py", line 341, in dbapi
from sqlite3 import dbapi2 as sqlite # try 2.5+ stdlib name.
File "C:\Users\user\Anaconda3\lib\sqlite3\__init__.py", line 23, in <module>
from sqlite3.dbapi2 import *
File "C:\Users\user\Anaconda3\lib\sqlite3\dbapi2.py", line 27, in <module>
from _sqlite3 import *
ImportError: DLL load failed: ‏‏entry module not found.
I've tried to install different libraries according to recommendations I found online:
pip install sqlite-devel
pip install sqlite3tools
pip install libsqlite3-dev
for each of the above I got the following error:
Could not find a version that satisfies the requirement "sqlite-devel <from versions: >
No matching distribution found for "sqlite-devel"
def zipcodes_list(st_items):
search = SearchEngine()
# If st_items is a single zipcode string.
if isinstance(st_items, str):
zc_objects = search.by_prefix(st_items)
# If st_items is a list of zipcode strings.
elif isinstance(st_items, list):
zc_objects = [n for i in st_items for n in search.by_prefix(str(i))]
else:
raise ValueError("arg 'st_items' must be of type str or list")
output = [str(i).split(" ", 1)[1].split(">")[0] for i in zc_objects]
return output

Related

Trying use openAI gym, getting a pyglet/openGL error on running

I am trying the following code:
import gym
env = gym.make('ma_gym:Switch2-v0')
done_n = [False for _ in range(env.n_agents)]
ep_reward = 0
obs_n = env.reset()
while not all(done_n):
env.render()
obs_n, reward_n, done_n, info = env.step(env.action_space.sample())
ep_reward += sum(reward_n)
env.close()
However, when I run it, I get the following error messages:
Advay#advays-mbp evolution-org-main % /Users/Advay/miniforge3/envs/evolution_env/bin/python "/Users/Advay/Library/Mobile Documents/com~apple~CloudDocs/Brown/Research/Rose Lab/evolution-org-main/magym-room-v0/runner.py"
/Users/Advay/miniforge3/envs/evolution_env/lib/python3.9/site-packages/gym/logger.py:34: UserWarning: WARN: Box bound precision lowered by casting to float32
warnings.warn(colorize("%s: %s" % ("WARN", msg % args), "yellow"))
Traceback (most recent call last):
File "/Users/Advay/miniforge3/envs/evolution_env/lib/python3.9/site-packages/gym/envs/classic_control/rendering.py", line 27, in <module>
from pyglet.gl import *
File "/Users/Advay/miniforge3/envs/evolution_env/lib/python3.9/site-packages/pyglet/gl/__init__.py", line 95, in <module>
from pyglet.gl.lib import GLException
File "/Users/Advay/miniforge3/envs/evolution_env/lib/python3.9/site-packages/pyglet/gl/lib.py", line 147, in <module>
from pyglet.gl.lib_agl import link_GL, link_GLU, link_AGL
File "/Users/Advay/miniforge3/envs/evolution_env/lib/python3.9/site-packages/pyglet/gl/lib_agl.py", line 43, in <module>
gl_lib = pyglet.lib.load_library(framework='/System/Library/Frameworks/OpenGL.framework')
File "/Users/Advay/miniforge3/envs/evolution_env/lib/python3.9/site-packages/pyglet/lib.py", line 124, in load_library
return self.load_framework(kwargs['framework'])
File "/Users/Advay/miniforge3/envs/evolution_env/lib/python3.9/site-packages/pyglet/lib.py", line 279, in load_framework
raise ImportError("Can't find framework %s." % path)
ImportError: Can't find framework /System/Library/Frameworks/OpenGL.framework.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/Advay/Library/Mobile Documents/com~apple~CloudDocs/Brown/Research/Rose Lab/evolution-org-main/magym-room-v0/runner.py", line 9, in <module>
env.render()
File "/Users/Advay/miniforge3/envs/evolution_env/lib/python3.9/site-packages/ma_gym/envs/switch/switch_one_corridor.py", line 183, in render
from gym.envs.classic_control import rendering
File "/Users/Advay/miniforge3/envs/evolution_env/lib/python3.9/site-packages/gym/envs/classic_control/rendering.py", line 29, in <module>
raise ImportError(
ImportError:
Error occurred while running `from pyglet.gl import *`
HINT: make sure you have OpenGL installed. On Ubuntu, you can run 'apt-get install python-opengl'.
If you're running on a server, you may need a virtual frame buffer; something like this should work:
'xvfb-run -s "-screen 0 1400x900x24" python <your_script.py>'
I know that the problem is somewhere in the render step but I unsure how to proceed with debugging. I am currently running the code in a conda virtual environment.
To check if the packages in question were installed correctly, I also tried:
import pyglet
import OpenGL
print("hi")
Which successfully printed "hi", confirming that the packages are installed.
Any help greatly appreciated!

How to correctly import latest libarchive for use on Mac OS

The release notes for libarchive state that because of an older version of libarchive being included within MacOS they recommend changing LD_LIBRARY_PATH to point towards the location of the recent copy of libarchive.
I've used this code to try and achieve that but I get an error message when I run the script.
import os
print os.environ.get('LD_LIBRARY_PATH') #Check what the current path is
os.environ['LD_LIBRARY_PATH'] = '/Library/Python/2.7/site-packages/'
print os.environ.get('LD_LIBRARY_PATH') #Check the variable has been set
import libarchive.public
Error:
None
/Library/Python/2.7/site-packages/
Traceback (most recent call last):
File "scratch.py", line 8, in <module>
import libarchive.public
File "/Library/Python/2.7/site-packages/libarchive/public.py", line 1, in <module>
from libarchive.adapters.archive_read import \
File "/Library/Python/2.7/site-packages/libarchive/adapters/archive_read.py", line 7, in <module>
import libarchive.calls.archive_read
File "/Library/Python/2.7/site-packages/libarchive/calls/archive_read.py", line 17, in <module>
c_archive_read_support_filter_all = libarchive.archive_read_support_filter_all
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 378, in __getattr__
func = self.__getitem__(name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 383, in __getitem__
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: dlsym(0x7fb08b741000, archive_read_support_filter_all): symbol not found
I cant find a great answer to this anywhere out there.
It is not clear from the tool documentation, but based on a thread: https://github.com/dsoprea/PyEasyArchive/issues/16 I set another environment variable to the place where the underlying c library could be found. In my case, it was put there by homebrew on my mac.
os.environ['LA_LIBRARY_FILEPATH']='/usr/local/opt/libarchive/lib/libarchive.dylib'
import libarchive.public
worked for me.

Using py-postgresql with SQLAlchemy raises No module named postgresql.driver

I want to use the py-postgresql driver with SQLAlchemy. However, I get the following ImportError. I am using Python 2.7.
Traceback (most recent call last):
File "/home/ed/projects/wiki/main.py", line 3, in <module>
from database import db_session as db
File "/home/ed/projects/wiki/database.py", line 5, in <module>
engine = create_engine('postgresql+pypostgresql://ed:noles98#127.0.0.1:5432/wiki', convert_unicode=True)
File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/__init__.py", line 386, in create_engine
return strategy.create(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/strategies.py", line 75, in create
dbapi = dialect_cls.dbapi(**dbapi_args)
File "/usr/lib/python2.7/dist-packages/sqlalchemy/dialects/postgresql/pypostgresql.py", line 65, in dbapi
from postgresql.driver import dbapi20
ImportError: No module named postgresql.driver

Python makes lib error when making FireFox Sync 1.5

I've tried to make my own server to new sync service in FireFox.
I used the following tutorial: https://docs.services.mozilla.com/howtos/run-sync-1.5.html .
When I wanted to check it by using make test I got the following error:
Traceback (most recent call last):
File "/home/jj/syncserver/local/local/lib/python2.7/site-packages/nose/loader.py", line 403, in loadTestsFromName
module = resolve_name(addr.module)
File "/home/jj/syncserver/local/local/lib/python2.7/site-packages/nose/util.py", line 311, in resolve_name
module = __import__('.'.join(parts_copy))
File "/home/jj/syncserver/local/local/lib/python2.7/site-packages/syncstorage/__init__.py", line 5, in <module>
import mozsvc.config
File "/home/jj/syncserver/local/local/lib/python2.7/site-packages/mozsvc/config.py", line 10, in <module>
from konfig import Config, SettingsDict
File "/home/jj/syncserver/local/local/lib/python2.7/site-packages/konfig/__init__.py", line 11, in <module>
from configparser import ConfigParser, ExtendedInterpolation
ImportError: cannot import name ExtendedInterpolation
What's happened?
configparser.ExtendedInterpolation does not exist in Python 2.
You need to use Python 3.

NameError: name '__builtin__' is not defined while installing SQLAlchemy

I've installed Python 2.7.2 on my Windows XP computer.
I recently installed SQLAlchemy 0.7.1 using 'python setup.py install'. During the installation, I got the following error messages:
byte-compiling C:\Python27\Lib\site-packages\sqlalchemy\sql\visitors.py to visitors.pyc
SyntaxError: ('invalid syntax', ('C:\\Python27\\Lib\\site-packages\\sqlalchemy\\sql\\visitors.py', 66, 34, 'class Visitable(object, metaclass=VisitableType):\n'))
When I try to import sqlalchemy, I get the following stack trace:
>>> import sqlalchemy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\sqlalchemy\__init__.py", line 12, in <module>
from sqlalchemy.sql import (
File "C:\Python27\lib\site-packages\sqlalchemy\sql\__init__.py", line 7, in <module>
from sqlalchemy.sql.expression import (
File "C:\Python27\lib\site-packages\sqlalchemy\sql\expression.py", line 32, in <module>
from sqlalchemy import util, exc
File "C:\Python27\lib\site-packages\sqlalchemy\util\__init__.py", line 7, in <module>
from .compat import callable, cmp, reduce, defaultdict, py25_dict, \
File "C:\Python27\lib\site-packages\sqlalchemy\util\compat.py", line 93, in <module>
callable = __builtin__.callable
NameError: name '__builtin__' is not defined
Other scripts work fine and all the functions in __builtin__ seem to be available.
I can't find any examples of similar problems on Google or in the SQLAlchemy documentation.
What's wrong?
UPDATE:
Uncommenting import __builtin__ in compat.py removed the first problem. Now I seem to have problems with visitors.py:
>>> import sqlalchemy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\sqlalchemy\__init__.py", line 12, in <module>
from sqlalchemy.sql import (
File "C:\Python27\lib\site-packages\sqlalchemy\sql\__init__.py", line 7, in <module>
from sqlalchemy.sql.expression import (
File "C:\Python27\lib\site-packages\sqlalchemy\sql\expression.py", line 35, in <module>
from sqlalchemy.sql.visitors import Visitable, cloned_traverse
File "C:\Python27\lib\site-packages\sqlalchemy\sql\visitors.py", line 66
class Visitable(object, metaclass=VisitableType):
^
SyntaxError: invalid syntax
Problem partially solved: everything started working when I rolled back to SQLAlchemy 0.6.8. An issue with 0.7.1 + Windows/2.6?

Categories