Python Package not found - python

I have created a virtual environment and installed all required packages and running the python code. all looks okay and not seen any issue. Later I have a requirement to connect to an api and get data. For this, I have installed requests==2.22.0 in the virtual environment and running the python code but end up with No module named "requests".
Could you please advise me what went wrong in this case to import the requests module into my code I appreciate you quick help.
Thanks,
Bhaskar.

Related

I am receiving and import error when trying to import cv2 in python (Ubuntu 18.04)

First of all, thank you very much for reading.
Some days ago I installed Python3 (3.6.9) and opencv 3.4.10 in an Ubuntu 18.04 desktop system. I needed to downgrade opencv to 3.4.0 after some compilation problems (not related to python3), so I removed opencv 3.4.10 by using the sudo make uninstall order, and tested that it was uninstalled as if I tried importing it in python I got the following error:
libopencv_hfs.so.3.4: cannot open shared object file: no such file or directory
I thought installing 3.4.0 version would solve the problem but now that it's installed, when I try to import it in a python3 script I am getting the same error. I think this error must be related to the way python3 references the import files. I think it's still pointing to the uninstalled version of 3.4.10, but I can not find the way to change it.
Could someone please help me with this issue?
Thank you very much.
Andrés.
Using a virtualenv would resolve the issue. Check this out on how to use : Installing packages using pip and virtual environments
Once you're done installing requirements in the virtualenv, run your python script there only to use the specified versions.
Hello again and thank you for you answers.
I have been able to solve the problem. Thought I had uninstalled the previous version of opencv, there was still a cv2.sofile in my python virtual environment path, and it had not been replaced by the new cv2.so, so python tried to import the old one instead of the new one.
The old cv2.so (the one that was referenced when I imported cv2 in python) was here --> ~/.virtualenvs/cv/lib/python3.6/site-packages/cv2.so
The cv2.so I wanted to be used when imported was here --> /usr/local/lib/python3.6/site-packages/cv2/cv2.so so I replaced the one in the virtual environment path with the one in the lib directory and that did the trick :)

Error Importing Requests Module in Flask Backend

I am currently trying to integrate a flask backend to my react web-app. In my flask subdirectory, I have installed requests module as shown below but I keep running into an unresolved import error although I have installed the module. I have tried to follow different troubleshooting suggestions online but none seem to work. Would really appreciate if someone can help me out.
This looks like that the terminal and the IDE use two different environments.
You should either create a virtual env with PyCharm directly, or choose the existing one.
Please read the PyCharm documentation:
https://www.jetbrains.com/help/pycharm/creating-virtual-environment.html
There, either choose "New environment" or "Existing environment".

VScode intellisense not recognizing pip intalled packages (python)

I'm just getting started with python. After installing python (3.6.8) and running VS code to learn some scripts, I found out that intellisense is not giving any suggesions for packages that I installed by pip
ex:
import numpy as np
x=np.ar(nothing shows here and even before typing the "ar", just shows a bunch of stuff that I typed earlier)
I'm sorry if I'm missing something, I'm literally a newbie.
Thank you.
Make sure that you selected the appropriate interpreter and environment that you installed into. Also make sure that the extension has finished loading and analyzing packages. Finally, you can use the Microsoft language server if you aren't already to see if it gives you better results than Jedi.

ANTLR3 python runtime not detected

I want to use fstpso package in python which needs ANTLR3 python runtime.
I downloaded antlr_python_runtime-3.1.3.tar.gz from http://www.antlr3.org/download/Python/ and ran the command sudo python setup.py install. The output of the command was
Installed /path/to/python/packages/antlr_python_runtime-3.1.3-py2.7.egg
But after this when I try to import fstpso module in python, it throws the error
The ANTLR3 python runtime was not detected; pyfuzzy cannot import FST-PSO's FLC files
I am using python 2.7.12 on linux.
Is there something I did wrong? Or I have to update any PATH in the environment?
Thanks for your help!!
I'm fst-pso main developer. In the last days I reimplemented the Sugeno reasoner from scratch, to finally remove the pufuzzy/ANTL3 dependency. I just uploaded the new package on PyPI.
Now you can pip install the new version of fst-pso (v 1.4.0); please let me know if that works correctly.

ImportError exception encountered while trying to use Fabric

I am using Ubuntu and virtualenv, and I am having this recurring problem, while attempting to use Fabric to create a deployment script. Fabric depends on paramiko, which depends on PyCrypto.
Each time I try to use Fabric, or PyCrypto directly, I get this error:
ImportError: cannot import name Random
I have tried reinstalling with pip install -U PyCrypto. I have also tried installing the python-crypto and python-crypto-dbg packages with Aptitude, to no avail. I still get the same error. Anyone have any ideas that might help me solve this problem? Thanks in advance!
It's possible that there's a file name collision in your the directory from which you're running Fabric. Do you have a file called Crypto.py in your project?
Can you get Crypto.Random to import from outside of your project directory? (but still using your virtualenv. Ipython is a big help here.)
I've had the same trouble in the past using Ubuntu. I no longer have a Ubuntu install available, but on my old 10.04 box, the file Random in the Crypto directory was missing. Make sure it exists, if it doesn't, that's the problem.

Categories