How to make a Flask application in venv works with Anaconda - python

I'm trying to start a flask application, with flask run, (which was working fine before I installed Anaconda), and I'm getting the following stack trace
Traceback (most recent call last):
File "C:\Users\Rodrigo\Anaconda3\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\Users\Rodrigo\Anaconda3\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\Rodrigo\Documents\Project1\frontEnd\venv\Scripts\flask.exe\__main__.py", line 5, in <module>
File "C:\Users\Rodrigo\Documents\Project1\frontEnd\venv\lib\site-packages\flask\__init__.py", line 19, in <module>
from jinja2 import Markup, escape
File "C:\Users\Rodrigo\Documents\Project1\frontEnd\venv\lib\site-packages\jinja2\__init__.py", line 82, in <module>
_patch_async()
File "C:\Users\Rodrigo\Documents\Project1\frontEnd\venv\lib\site-packages\jinja2\__init__.py", line 78, in _patch_async
from jinja2.asyncsupport import patch_all
File "C:\Users\Rodrigo\Documents\Project1\frontEnd\venv\lib\site-packages\jinja2\asyncsupport.py", line 13, in <module>
import asyncio
File "C:\Users\Rodrigo\Anaconda3\lib\asyncio\__init__.py", line 8, in <module>
from .base_events import *
File "C:\Users\Rodrigo\Anaconda3\lib\asyncio\base_events.py", line 39, in <module>
from . import events
File "C:\Users\Rodrigo\Anaconda3\lib\asyncio\events.py", line 14, in <module>
import contextvars
File "C:\Users\Rodrigo\Anaconda3\lib\contextvars.py", line 1, in <module>
from _contextvars import Context, ContextVar, Token, copy_context
ModuleNotFoundError: No module named '_contextvars'
The Python version at the system level is 3.7.3
The Python version at venv level is 3.7.0
I've already tried to install contextvars, but it only upgraded an older version and did not fix the problem. In both system level and venv level contextvars requisite is already satisfied.
I'm running this on Windows 10.
Any idea on what can be causing this?

I have the same issue when using python 3.7.2 on Windows 7.
This is a known bug and should be resolved.
https://bugs.python.org/issue34691
Updating to python 3.7.3 resolved the issue (for me).
Try to update your venv level to 3.7.3

Related

Error message about 'libsqlite3' when activate environment in jupyter Notebook

I try to activate my env to Jupyter notebook by using:
python -m ipykernel install --user --name native --display-name "python-gpu"
But error message:
Traceback (most recent call last):
File "/Users/nianhua/opt/anaconda3/envs/native/lib/python3.10/runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/Users/nianhua/opt/anaconda3/envs/native/lib/python3.10/runpy.py", line 86, in _run_code
exec(code, run_globals)
File "/Users/nianhua/opt/anaconda3/envs/native/lib/python3.10/site-packages/ipykernel/__main__.py", line 2, in <module>
from ipykernel import kernelapp as app
File "/Users/nianhua/opt/anaconda3/envs/native/lib/python3.10/site-packages/ipykernel/kernelapp.py", line 18, in <module>
from IPython.core.application import (
File "/Users/nianhua/opt/anaconda3/envs/native/lib/python3.10/site-packages/IPython/__init__.py", line 53, in <module>
from .terminal.embed import embed
File "/Users/nianhua/opt/anaconda3/envs/native/lib/python3.10/site-packages/IPython/terminal/embed.py", line 15, in <module>
from IPython.core.interactiveshell import DummyMod, InteractiveShell
File "/Users/nianhua/opt/anaconda3/envs/native/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 73, in <module>
from IPython.core.history import HistoryManager
File "/Users/nianhua/opt/anaconda3/envs/native/lib/python3.10/site-packages/IPython/core/history.py", line 11, in <module>
import sqlite3
File "/Users/nianhua/opt/anaconda3/envs/native/lib/python3.10/sqlite3/__init__.py", line 57, in <module>
from sqlite3.dbapi2 import *
File "/Users/nianhua/opt/anaconda3/envs/native/lib/python3.10/sqlite3/dbapi2.py", line 27, in <module>
from _sqlite3 import *
ImportError: dlopen(/Users/nianhua/opt/anaconda3/envs/native/lib/python3.10/lib-dynload/_sqlite3.cpython-310-darwin.so, 0x0002): Symbol not found: _sqlite3_enable_load_extension
Referenced from: /Users/nianhua/opt/anaconda3/envs/native/lib/python3.10/lib-dynload/_sqlite3.cpython-310-darwin.so
Expected in: /usr/lib/libsqlite3.dylib
It seems like something is wrong with my libsqlite3, but it goes well in my terminal.
My laptop is a Macbook pro with M1Pro. And I'm building an arm64 python environment in M1 version Anaconda.
Does anyone know how I can get around this?
I had the same problem and I solved by installing a newer version:
mamba install sqlite=3.40.0
always checking that the new library is coming from conda-forge/osx-arm64.

Unable to import a .pyx version between Python 3.6 and Python 3.7

I am trying to get the program in this repository to work. If I am on Python version 3.6 then the I have no issues, however, if I am on Python version 3.7 then I get the following error:
Traceback (most recent call last):
File "/home/user/anaconda3/envs/another/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/home/user/anaconda3/envs/another/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/user/ThirdYearProject/SiamMask/tools/demo.py", line 7, in <module>
from SiamMask.tools.test import *
File "/home/user/ThirdYearProject/SiamMask/tools/test.py", line 28, in <module>
from SiamMask.utils.pyvotkit.region import vot_overlap, vot_float2str
File "/home/user/ThirdYearProject/SiamMask/utils/pyvotkit/__init__.py", line 9, in <module>
from . import region
ImportError: cannot import name 'region' from 'SiamMask.utils.pyvotkit' (/home/user/ThirdYearProject/SiamMask/utils/pyvotkit/__init__.py)
All that the __init__.py file contains is this:
from . import region
It seems that region is a .pyx module. Here is the directory structure of it.
How come the import is working fine on Python 3.6, but is unable to import on version 3.7? Both are fresh conda environements, which have not had anything installed apart from opencv, torch + cuda.

Error with pre-commit: No module named 'pwd', failes pylint(examples.code)

I'm a newbie to pre-commit. I'm trying to locally check a single python file I'd staged after I thought I'd had pre-commit installed on my PC (Windows 10) and properly installed in the directory. Here's what happens when I try to commit a file from the git bash shell:
$ git commit -m "test pre-commit"
black....................................................................Passed
reuse....................................................................Failed
- hook id: reuse
- exit code: 1
Traceback (most recent call last):
File "C:\Users\mikem\Anaconda3\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\Users\mikem\Anaconda3\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\mikem\.cache\pre-commit\repo8wyuxez6\py_env-python3\Scripts\reuse.EXE\__main__.py", line 4, in <module>
File "c:\users\mikem\.cache\pre-commit\repo8wyuxez6\py_env-python3\lib\site-packages\reuse\_main.py", line 14, in <module>
from . import (
File "c:\users\mikem\.cache\pre-commit\repo8wyuxez6\py_env-python3\lib\site-packages\reuse\download.py", line 17, in <module>
from ._util import (
File "c:\users\mikem\.cache\pre-commit\repo8wyuxez6\py_env-python3\lib\site-packages\reuse\_util.py", line 26, in <module>
from debian.copyright import Copyright
File "c:\users\mikem\.cache\pre-commit\repo8wyuxez6\py_env-python3\lib\site-packages\debian\copyright.py", line 59, in <module>
from debian import deb822
File "c:\users\mikem\.cache\pre-commit\repo8wyuxez6\py_env-python3\lib\site-packages\debian\deb822.py", line 321, in <module>
import debian.changelog
File "c:\users\mikem\.cache\pre-commit\repo8wyuxez6\py_env-python3\lib\site-packages\debian\changelog.py", line 93, in <module>
import pwd
ModuleNotFoundError: No module named 'pwd'
Check Yaml...........................................(no files to check)Skipped
Fix End of Files.........................................................Passed
Trim Trailing Whitespace.................................................Passed
pylint (library code)....................................................Passed
pylint (examples code)...................................................Failed
- hook id: pylint_examples
- exit code: 1
Executable `/usr/bin/env` not found
Can someone explain what this means and how I fix it? Thanks!

I'm getting ModuleNotFoundError: No module named _socket on ubuntu 18.04

I installed Anaconda3 on ubuntu and changed the path to ~/anaconda/bin in .bashrc file then I'm trying to install keras It's throwing this error.
hemanth#specter:~$ python3 -m pip install keras
Traceback (most recent call last):
File "/home/hemanth/anaconda3/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/home/hemanth/anaconda3/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/hemanth/anaconda3/lib/python3.7/site-packages/pip/__main__.py", line 16, in <module>
from pip._internal import main as _main # isort:skip # noqa
File "/home/hemanth/anaconda3/lib/python3.7/site-packages/pip/_internal/__init__.py", line 19, in <module>
from pip._vendor.urllib3.exceptions import DependencyWarning
File "/home/hemanth/anaconda3/lib/python3.7/site-packages/pip/_vendor/urllib3/__init__.py", line 8, in <module>
from .connectionpool import (
File "/home/hemanth/anaconda3/lib/python3.7/site-packages/pip/_vendor/urllib3/connectionpool.py", line 7, in <module>
from socket import error as SocketError, timeout as SocketTimeout
File "/home/hemanth/anaconda3/lib/python3.7/socket.py", line 49, in <module>
import _socket
ModuleNotFoundError: No module named '_socket'
I tried this command and it is working fine.
however, try to install socket using pip install sockets and then again try installing keras.

Trying to install mysql-python: "No module named urllib3"

I'm trying to look around on this issue but so far nothing I've found has fixed it. I am not that familiar with Python and I'm working with someone else's script. I am on Windows 10 (64-bit).
Executing this command: pip install mysql-python
And getting this error:
Traceback (most recent call last):
File "C:\Python27\Lib\runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "C:\Python27\Lib\runpy.py", line 72, in _run_code
exec code in run_globals
File "C:\Python27\Scripts\pip.exe\__main__.py", line 5, in <module>
File "C:\Python27\lib\site-packages\pip\__init__.py", line 15, in <module>
from pip.vcs import git, mercurial, subversion, bazaar # noqa
File "C:\Python27\lib\site-packages\pip\vcs\mercurial.py", line 9, in <module>
from pip.download import path_to_url
File "C:\Python27\lib\site-packages\pip\download.py", line 38, in <module>
from pip._vendor import requests, six
File "C:\Python27\lib\site-packages\pip\_vendor\requests\__init__.py", line 58, in <module>
from . import utils
File "C:\Python27\lib\site-packages\pip\_vendor\requests\utils.py", line 26, in <module>
from .compat import parse_http_list as _parse_list_header
File "C:\Python27\lib\site-packages\pip\_vendor\requests\compat.py", line 7, in <module>
from .packages import chardet
File "C:\Python27\lib\site-packages\pip\_vendor\requests\packages\__init__.py", line 29, in <module>
import urllib3
ImportError: No module named urllib3
The python module that you are trying to install will probably require you to compile it which makes the task much harder for a newbie.
Instead, I would recommend you to use a pure-python module like https://github.com/PyMySQL/PyMySQL -- which is much easier to install because you do not have to compile it.
Usually I recommend anyone that is trying to work with databases in Python to use SQLAlchemy, mainly because this allows you to use a single interface when you deal with the database, one that does not depends on the database-driver being used.
Read the answer from
python3 sqlalchemy pymysql connect string in order to get an idea about how to use pymysql via sqlalchemy.
wget https://pypi.python.org/packages/3b/f0/e763169124e3f5db0926bc3dbfcd580a105f9ca44cf5d8e6c7a803c9f6b5/urllib3-1.16.tar.gz#md5=fcaab1c5385c57deeb7053d3d7d81d59
tar xvf urllib3-1.16.tar.gz && cd urllib3-1.1
python setup.py install

Categories