ModuleNotFoundError: No module named 'pyproj._network' - spyder

I am trying to run Python Code on Spyder for scientific computing. I use geometric information from shape files using geopandas. Installing geopandas was already difficult but I finally managed. However now I have another issue, that a module called 'pyproj._network' is not found.
I checked and the module is there and was also added to the path using the PYTHONPATH manager of Spyder.
Now I dont know anymore- any help very much appreciated!
Thanks!
`ModuleNotFoundError: No module named 'pyproj._network'
Entering post mortem debugging...
c:\users\stefano-work\miniconda3\lib\site-packages\pyproj\network.py(10)()
8 import certifi
9
---> 10 from pyproj._network import ( # noqa: F401
11 _set_ca_bundle_path,
12 is_network_enabled,
`

Related

SyntaxError: future feature annotations is not defined for dockerize

Im trying to dockerize my project, but ran into the following error, not sure what is the error about.
Traceback (most recent call last):
File "server/main.py", line 5, in
from fastai.vision.all import *
File "/usr/local/lib/python3.6/site-packages/fastai/vision/all.py", line 1, in from . import models
File "/usr/local/lib/python3.6/site-packages/fastai/vision/models/init.py", line 1, in
from . import xresnet
File "/usr/local/lib/python3.6/site-packages/fastai/vision/models/xresnet.py", line 12, in
from ...torch_basics import *
File "/usr/local/lib/python3.6/site-packages/fastai/torch_basics.py", line 9, in
from .imports import *
File "/usr/local/lib/python3.6/site-packages/fastai/imports.py", line 30, in
from fastcore.all import *
File "/usr/local/lib/python3.6/site-packages/fastcore/all.py", line 3, in
from .dispatch import *
File "/usr/local/lib/python3.6/site-packages/fastcore/dispatch.py", line 4
from future import annotations
^
SyntaxError: future feature annotations is not defined
Im doing this on VSCode
Managed to trouble shoot the problem and resolved it.
For python version issue
Dockerfile to change python version from 3.6 to 3.10
for the various requirement issue
update requirement.txt to latest versions as prompted by the terminal as you run the dockerize process in the terminal.
hope this helps for all future people who encounters the same problem

Ray cluster ModuleNotFoundError

I am new to Ray and wanted to set up a cluster with some dependencies. I first set up a cluster with some dependencies supported out of the box and everything worked fine. Now, I have the following scenario that I simplified to this demonstration. There is a problem with joblib even though I specify it in a runtime env as to be downloaded with pip and then pass it to ray.init.
from ray.util.joblib import register_ray
import joblib
import ray
import numpy as np
# connect to ray
runtime_env={"pip": ["joblib"]}
ray.init(address='auto', _redis_password=..., runtime_env=runtime_env)
#ray.remote(num_cpus=1)
def train_ray(...):
...
register_ray()
with joblib.parallel_backend('ray'):
...
return ...
I get the following error:
from ray.util.joblib import register_ray
File "/home/ray/anaconda3/lib/python3.7/site-packages/ray/util/joblib/__init__.py", line 1, in <module>
from joblib.parallel import register_parallel_backend
ModuleNotFoundError: No module named 'joblib'
command terminated with exit code 1
Thanks for any suggestions.

"'cv2.face' has no attribute 'LBPHFaceRecognizer_create'" but if installed from pip the gui gives qt thread error

I'm trying to run a python script for a basic face recognition but when running after installing from pip I get the error:
QObject::moveToThread: Current thread (0x24c8e90) is not the object's thread (0x20da6d0).
Cannot move to target thread (0x24c8e90)
I found this question and it solved the problem but after that I get this error:
Traceback (most recent call last):
File "face_recognition.py", line 21, in
recognizer = cv2.face.LBPHFaceRecognizer_create()
AttributeError: module 'cv2.face' has no attribute 'LBPHFaceRecognizer_create'
I found many answers (for example) to this problem but all suggested to install the opencv-contrib-python package from pip.
How can I include the needed package from apt-get?
The code where I get the error:
import cv2
import numpy as np
recognizer = cv2.face.LBPHFaceRecognizer_create()

PyLint not recognizing cv2 members

I am running pylint on an opencv project and I am getting many pylint errors in VS code about members not being present.
Example code:
import cv2
cv2.imshow(....)
Errors obtained:
However , the code runs correctly without any errors.
Versions : pylint 1.8.1 , astroid 1.6.0
This is from pylint. You can generate a pylint config file in the root of your project with this command:
(I find this to be helpful if you work in a team or on different computers from the same repo)
pylint --generate-rcfile > ~/.pylintrc
At the beginning of the generated .pylintrc file you will see
# A comma-separated list of package or module names from where C extensions may
# be loaded. Extensions are loading into the active Python interpreter and may
# run arbitrary code.
extension-pkg-whitelist=
Add cv2 so you end up with
# A comma-separated list of package or module names from where C extensions may
# be loaded. Extensions are loading into the active Python interpreter and may
# run arbitrary code.
extension-pkg-whitelist=cv2
Save the file.
The lint errors should disappear.
On VScode: CTRL + Shift + P
Choose "Preferences: Open Settings (JSON)"
Add this line into JSON file:
"python.linting.pylintArgs": ["--generate-members"]
Done, it works for me
Note: Make sure you choose "Preferences: Open Settings (JSON)", not "Preferences: Open Default Settings (JSON)"
Setting File would look like
{
"workbench.iconTheme": "vscode-icons",
"python.dataScience.sendSelectionToInteractiveWindow": true,
"kite.showWelcomeNotificationOnStartup": false,
"python.dataScience.askForKernelRestart": false,
"python.dataScience.jupyterServerURI": "local",
"python.pythonPath": "/usr/bin/python3",
"workbench.colorTheme": "Monokai",
"vsicons.dontShowNewVersionMessage": true,
"python.linting.pylintArgs": ["--generate-members"] }
Try import cv2 like this:
from cv2 import cv2
Yes it is because the extension has not been installed.
Set this: extension-pkg-whitelist=cv2 and you're good to go.
However it may not detect the functions or modules implemented in cv2
Here the code snippet for the settings.json file in MS V Code
"python.linting.pylintArgs":["--extension-pkg-whitelist=cv2"]
I didn't have to change anything in the pylint Jason file like the most of the answers here My solution is to change the import statement to the form below
from cv2 import cv2
Eventually, cv2 members can be used!
In VSCode, edit the Settings JSON (Ctrl+Shift+P, > "Preferences: Open Settings JSON)
Then, paste the following into the JSON:
"python.linting.pylintArgs": [
... // prievious arguments
"--generated-members=cv2.*"
]
Don't know why, but other solutions (allowlist, etc) weren't working for me, and I didn't want ot create the .pylintrc file.
I used below config settings in settings.json of vscode and it helped me avoid the unessential flags by pylint, and also got intellisense for cv2 working,
it it doesn't work try uninstalling and deleting cv2 packages from C:\Anaconda3\envs\demo1\Lib\site-packages folder, and reinstalling opencv-python package
{
"python.linting.pylintEnabled": true,
"python.linting.enabled": true,
"python.linting.pylintArgs": [
"--extension-pkg-whitelist=cv2"
]
}

Library not loaded: /usr/local/lib/libhdf5.9.dylib

After "brew upgrade", I found I cannot use Pytables on my Mac.
import tables as tb
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-29-57032f570037> in <module>()
----> 1 import tables as tb
/usr/local/lib/python2.7/site-packages/tables/__init__.py in <module>()
80
81 # Necessary imports to get versions stored on the cython extension
---> 82 from tables.utilsextension import (
83 get_pytables_version, get_hdf5_version, blosc_compressor_list,
84 blosc_compcode_to_compname_ as blosc_compcode_to_compname,
ImportError: dlopen(/usr/local/lib/python2.7/site-packages/tables/utilsextension.so, 2): Library not loaded: /usr/local/lib/libhdf5.9.dylib
Referenced from: /usr/local/lib/python2.7/site-packages/tables/utilsextension.so
Reason: image not found
I found that instead of having libhdf5.9.dylib in the directory, I have libhdf5.10.dylib now.
I can uninstall and install hdf5 without a problem and I also tried to reinstall tables.
I'm not sure how to solve this problem.
You need to reinstall tables. If you are using a recent version of pip, you also need to make sure you don't use a cached version of pytables that was built against the old libhdf. You can do this with pip install -U --force-reinstall --no-binary tables tables.
Problem solved by installing the developing version from GitHub:
pip install git+https://github.com/PyTables/PyTables.git#develop#egg=tables

Resources