Unable to import Libraries even though Installed in Anaconda on Pycharm - python-3.x

I am using Ubuntu 18.10(dual Boot win10), I have installed anaconda (conda version- 4.6.7) on ubuntu. After this Installation I installed Pycharm via snap on Command Prompt. Since Pycharm(version - 2018.3.5) didnt Detect my python Location automatically I set the python Interpreter via
Adding Location ->System Interpreter (As I didn't want any Venv) -> Path
But when I try to import opencv in Pycharm it says
ModuleNotFoundError: No module named 'cv2'
Python3.6 in Anaconda Bin is shown to which I have linked in Pycharm (I have also tried other Python files there as well but no luck)
When I run in Terminal: python3 -c 'import sys; print(sys.path)'
It shows:
['', '/usr/lib/python36.zip', '/usr/lib/python3.6', '/usr/lib/python3.6
/lib-dynload', '/usr/local/lib/python3.6/dist-packages', '/usr/local
/lib/python3.6/dist-packages/setuptools-39.1.0-py3.6.egg', '/usr/lib`/python3
/dist-packages']
So could anyone help me out in this?? Thank You in Advance!!
Edit 1:
I am also unable to access any of the libraries from terminal Itself. So Could anyone help me with that as well. Should I export path of this Python in Anaconda bin folder to bashrc file in Ubuntu?
Edit 2:
The libraries affected is not just opencv. There are few other Libraries like Portaudio which are affected as well along with Opencv

Related

Pandas install or import in IBM SPSS Statistics Version 26

I have installed the latest version of IBM SPSS Statistics(Version 26) which has pre installed python 3.4 and 2.7. i am trying to use version 3.4 python. i am able to import modules like pip , sys , os etc. i tried pandas the same way. i am unable to do so. getting error no module found. Hence going through our forum and IBM support did the following changes.
received the following error
1) tried pointing the site-packages via
import sys
# Assuming windows and standard python folder here.
sys.path.append(r"D:\Python34\Lib\site-packages")
2) changed the path in the settings of SPSS
3) Tried installing pip in the below folder as suggested in the forum but got message i have already installed the updated version.
C:\Program Files\IBM\SPSS\Statistics\Subscription\Python3
4) following versions of python were installed
have tried what i could. Need your expertise help to fix the same which will help me to install/use modules needed for SPSS. Thanks.
This is going to be painful to explain, I'll do my best.
As far as I can tell, you're on windows. Usually when we need a new package, we just open cmd and type pip install xxx (assume you added python to path when installing it). The reason that this works, is because when you type pip install xxx in cmd, windows recognize pip to be a command because python path is in system variables. Windows know that I can execute pip install with this python path.
However for SPSS python (3.4), that python had a different path in the system. Thus when you only have the 3.7 or 3.8 python in path, windows cannot install package to you 3.4 python, and I'm not sure if you can have more than one python path in system.
In order to fix this, you need to first figure out what's the path to your 3.4 python, then in this page you can follow the instruction to remove your 3.7 or 3.8 python in path, and add your 3.4 path, then you can do pip install xxxx for whatever package you want
I did the same thing with a arcgis python distribution, hope this works for you. If the attached page does not work, just google add python path to windows and look for a instruction that works on you PC
Oh and the reason that you can import pip, sys and some other package but not pandas, is because python is 'battery included', it comes with tons of packages pre-installed for additional functionality, but pandas is not one of them.
Fixed it since my ananconda had version 3.7 .i created virtual environment and installed 2.7 python with anaconda package. Pointed SPSS to the 2.7 folder and was able to import pandas.

Unable to import sqlite3 using Anaconda Python

I am trying to do the following in Python 3.7.1 on Windows
import sqlite3
but I get the following error message
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "c:\programdata\anaconda3\lib\sqlite3\__init__.py", line 23, in <module>
from sqlite3.dbapi2 import *
File "c:\programdata\anaconda3\lib\sqlite3\dbapi2.py", line 27, in <module>
from _sqlite3 import *
ImportError: DLL load failed: The specified module could not be found.
I have searched for a solution to the problem for quite a while now to no avail. I have also successfully run pip install pysqlite3 on the Anaconda prompt, but the import still fails. What do?
I got this working on windows by downloading: the sqlite3 dll (find your system version)
And placing it into the folder: C:\Users\YOURUSER\Anaconda3\DLLs
(Depending on how you installed Anaconda, this may have to be placed into
the following folder: C:\ProgramData\Anaconda3\DLLs)
According to #alireza-taghdisian, you can locate the exact path of
your conda environments (where you need to copy the sqlite3 dll) by typing:
conda info --envs on your anaconda prompt.
Locate the sqlite3.dll file. In my case it was in following folder
C:\Users\Admin\anaconda3\Library\bin
where C:\Users\Admin\anaconda3 is the folder where Anaconda was installed
Add this to PATH in environment variables, and it should work then.
Try copying the sqlite3.dll from the
C:\Users\YOURUSER\anaconda3\Library\bin
folder to
C:\Users\YOURUSER\Anaconda3\DLLs
Please check https://github.com/jupyter/notebook/issues/4332
I added anaconda root/Library/bin to my PATH and now it works!
Add CONDA_DLL_SEARCH_MODIFICATION_ENABLE=1 to your environment variables.
before executing the program, enter conda activate in your shell.
I had tried all above solutions But for me and my system I got to know that
I downloaded Python in C:\Python27 hence there is dll folder in python C:\Python27\DLLs
I installed Sqlite3.dll in my above dll folder
May be this solution will help you because it completely depends on where do you install your python
Happy coding :)
I put the sqlite3.dll in the path folder of my Python venv and still wont work. I suspected it is a path problem.
(In my case: E:\Virtual_Env\mini_zinc\env\Scripts)
I found in my case I messed up installation in a virtual evn, somehow using an anaconda python kernel within a Python venv.
I reinstall the Python Venv and check the python version after installed Env is correct (not the Anaconda python), then proceed with Jupyter Notebook (or Juyterlab) and works fine.
I was able to resolve this issue by putting sqlite3.dll file in the C:\Users<USERID>\AppData\Local\conda\conda\envs<ENV NAME>\DLLs.
Download sqlite3.dll file from https://www.sqlite.org/download.html
or copy it from C:\ProgramData\Anaconda3\DLLs\
I found the #elgsantos useful. But for those who are new to Python and Conda like me, I would like to add a little bit of details.
1- I use miniconda3 for creating new environment.
2- interestingly, I got two installation path on my computer for conda: the first one (the obvious) is located on "C:\Users\taghdisian\miniconda3". The second one is on "C:\Users\taghdisian\AppData\Local\r-miniconda". The latter is the primary path that you need to copy your sqlite3 files into the envs folder. I copy them in the "C:\Users\taghdisian\AppData\Local\r-miniconda\envs\sdr3.9\DLLs" in which the sdr3.9 is one of my virtual Condo environment.
you can locate the exact path of your conda environments (where you need to copy sqlite3) by typing the conda info --envs on your anaconda prompt.
I hope this help.
got the same error while loading the jupyter notebook from other conda prompt than "base" environment.
[1]: https://i.stack.imgur.com/2DW7E.png
Resolved by installing sqlite package
(nlpenv) C:\Users\arunk>conda install sqlite
launching
*
(nlpenv) C:\Users\arunk>jupyter notebook

How to solve ModuleNotFound Error in IDLE?

I am using ubuntu 18.04. I first installed Python along with anacondafrom terminal whose version is 3.7.0 and I have launched Jupyter notebook and Spyder as well. Then I installed IDLE whose version is 3.6.6+ and I am currently working in IDLE but then when I tried to import module,it shows the error: No module found. I checked for the path as well for both in IDLE and Terminal which are different.How do I solve this problem?
when I checked the python path,
In terminal,
/home/reema/anaconda3/lib/python37.zip:/home/reema/anaconda3/lib/python3.7:/home/reema/anaconda3/lib/python3.7/lib-dynload:/home/reema/anaconda3/lib/python3.7/site-packages
In IDLE,
['', '/home/reema', '/usr/bin', '/usr/lib/python36.zip', '/usr/lib/python3.6', '/usr/lib/python3.6/lib-dynload', '/usr/local/lib/python3.6/dist-packages', '/usr/lib/python3/dist-packages']
I tried appending in IDLE but it doesn't work.
Your problem is due to the different interpreters installing modules in different paths, and because the default interpreter at the command prompt is likely 3.7, while the installed Idle uses 3.6
The answer to your problem is to use pip to install new modules and invoke pip as follows
$ python3.x -m pip install ...
This way you know which interpreter is called, and each times the correct version of pip is invoked and, each time, the module is installed in the correct path for a given interpreter.
I have to add that, as far as I can tell, the Anaconda distribution does not support Idle.

Pycharm, opencv fails to load dll, works on prompt

After installing miniconda with python 3.7 I do the following:
conda create --name opencv_test python=3.7
conda activate opencv_test
conda install -c anaconda opencv
Then to test the environement I do:
python
>>> import cv2
>>> exit()
Everything goes according to plan
Then if I launch PyCharm or vs code, set my new environment as the interpreter and create a simple file that contains only
import cv2
On launch I get:
ImportError: DLL load failed: The specified module could not be found.
What I learned from the internets:
This, this and this, all those posts refer to a problem that seems similar, the difference being that the issue for me only happens when using IDEs
What I tried before posting here:
Recreating the environment multiple times switching channels.
As it seemed to be a path issue, I added the paths which contained opencv dll to the environment paths in PyCharm settings one at a time
What I just tried after spending a considerable amount of time creating this post:
conda update conda
This weirdly downgrades python to 3.6
conda create --name opencv_test_2 python=3.6
conda activate opencv_test_2
conda install -c anaconda opencv
This seems to fix all the issues but:
I don't know what just happened and why the issue only appeared on IDEs
I'd like to use python 3.7
So in short, why when using python 3.7 and PyCharm I seem to be unable to import opencv even if it works on command line?
Thanks in advance.

add python3 library to python3.6 path

hello I'm new to python3 and python3.6, I usually use pip3 install to add old libraries to my python3 path.
I recently picked up python3.6 for managing my home servers with its asyncio functionalities however my python3.6 interpreter is unable to locate pwnlibs and am thus unable to reuse my old code.
I tried:
import sys
import os
sys.path.append(os.path.abspath(pwn.__file__))
import pwn
debugging results:
on python3.4 os.path.abspath(pwn.__file__) returns the correct path to the library
While sys.path.append is a valid means to add to your python path at runtime, you can't get the path from a module you have not yet loaded.
Instead you should install your packages using pip3 or in a specific location and add that to your path either at runtime or via the PYTHONPATH environment variable.
I would guess since you mentioned pip3 already however that you had the pwn package already installed when you tried with 3.4 and your install of Python 3.6 is not using the same paths as your Python 3.4 install. Try comparing your python paths from 3.4 with 3.6 by comparing the output from sys.path.
Lastly, just as a note, if you are using the pwntools package, it doesn't yet support Python 3, so if you are simply copying the folder, be aware it might not function correctly or at all.

Resources