Getting error in pycharm terminal while running pytest command - import

I am getting the below error while running a pytest file in pycharm terminal
ImportError: Error importing plugin "main": No module named 'UserDict'
screenshot

Related

ImportError: No module named pytesseract on Jupiter lab and VSCode but not my local

I have tried running a ProcessImage.py file in which I import the package pytesseract in Jupiter Lab and VSCode.
This is the error that pops out :
import pytesseract
ImportError: No module named pytesseract
I already know that pytesseract is installed in my environment because with conda list:
pytesseract 0.3.2 py_0 conda-forge
pytest 5.3.5 py38_0 coda-forge
However, if I run my ProcessImage.py file on my local no error is prompted.
I know the error is related to paths in Jupiter Lab and VsCode but I can't seem to find a solution.
Have you tried to launch your python file using Ctrl+F5 command for run?
I had this same ImportError when trying to launch my python program using the .run extension. It persistently started python 2.7 while my environment was using Python3. I first thought that it was a VS code error but it wasn't.

installing python package in sagemaker sparkmagic pyspark notebook

I want to install new libraries in a running kernel (not bootstrapping). I'm able to create a sagemaker notebook, which is connected to a EMR cluster, but installing package is a headache.
Unable to install packages on notebook. I've tried several methods like installing packages via terminal in jupyterLab.
$ conda install numba
The installation seems to be working fine on conda_pytorch_p36 notebook, but the packages are not installed on SparkMagic (pyspark) notebook.
Error code:
An error was encountered:
No module named numba
Traceback (most recent call last):
ImportError: No module named numba
The jupyter magic command also doesn't work only in pyspark notebook
!pip install keras
Error:
An error was encountered:
invalid syntax (<stdin>, line 1)
File "<stdin>", line 1
!pip install keras
^
SyntaxError: invalid syntax
Based on answer in a github post, neither did this work
from subprocess import call
call("pip install dm-sonnet".split(" "))
when you are running $ conda install numba via the terminal in JupyterLab,
it's actually succeeding the installation on your local environment. The thing is, when you are using Sparkmagic as your kernal, the code in the cells are always running on the spark cluster, not on the local notebook environment. To run the content of a cell locally you should write %%local in the beginning of the cell. After that everything in that cell will run locally and the installed module will be available.
Otherwise you should install the module on the remote spark cluster.
Read more here:
https://github.com/jupyter-incubator/sparkmagic/blob/master/examples/Pyspark%20Kernel.ipynb

Using pip in conda for SCCmecfinder install from CGE errors

I want to install SCCmecfinder from CGE (bitbucket). Im in Ubuntu (18.04.2) and using conda (4.7.5) with pip to install. Is this the best way to go about it, or directly using python outside of conda be better?
(NB: I'm very new to all of this and learning on the fly with low skill level, so please explain clearly and simply.)
I created a new environment in Anaconda3/envs/SCCmecfinder, activated it and used:
pip install git+https://bitbucket.org/genomicepidemiology/sccmecfinder
this returned error code:
python setup.py egg_info" failed with error code 1 in /tmp/pip-req-build-92mzn1kf/
I followed feedback from others and used:
pip install --upgrade setuptools
retried the install instruction as above and this returned error code:
"python setup.py egg_info" failed with error code 1 in /tmp/pip-req-build-92mzn1kf/
I deactivated the environment, installed pip into it, reactivated it and retried the installation line again. New error returned - see below:
final error message:
ERROR: Complete output from command python setup.py egg_info:
ERROR: Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/sharb/anaconda3/envs/SCCmecfinder/lib/python3.7/tokenize.py", line 447, in open
buffer = _builtin_open(filename, 'rb')
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/pip-req-build-pobis9bg/setup.py'
----------------------------------------
ERROR: Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-req-build-pobis9bg/
The repository at https://bitbucket.org/genomicepidemiology/sccmecfinder doesn't have setup.py so it's not pip-installable.
All files in the repository are scripts (not libraries) so just copy them to any directory in your $PATH and make them executable.

Use AREPL within VScode using a WSL interpreter

I have a WSL environment running python and venv.
Besides that I have VSCode running in Windows with AREPL
I have no problem accessing my python venv including pip modules using the VSCode terminal. AREPL however seems to fail to recognize my pip plugins. My guess is that AREPL is using the Windows Python version to run the code instantly. However the WSL python venv does not generate a python.exe I could point my AREPL interpreter to.
So my question is:
Can I run AREPL on Windows VSCode to validate code that requires PIP modules that are NOT installed in Windows, but are installed on WSL within a venv.
I've tried Changing AREPL Python Path to either Python venv, WSL or Windows Python:
"D:\Scripting\Python\venvs\automation\bin\python"
"C:\Windows\System32\wsl.exe" (nothing happens as I type)
"C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1264.0_x64__qbz5n2kfra8p0\python.exe" (generates error)
Error when using venv location:
Error in the AREPL extension!
Error running python with command: D:\Scripting\Python\venvs\automation\bin\python -u C:\Users\user\.vscode\extensions\almenon.arepl-1.0.16\node_modules\arepl-backend\python\python_evaluator.py
Error: spawn D:\Scripting\Python\venvs\automation\bin\python ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:232:19)
at onErrorNT (internal/child_process.js:407:16)
at process._tickCallback (internal/process/next_tick.js:63:19)
Are you sure you have installed python 3 and it is in your PATH?
You can download python here: https://www.python.org/downloads/
Error when using WSL:
Nothing happens
Error when using windows python:
Traceback (most recent call last):
line 1, in <module>
ModuleNotFoundError: No module named 'requests'
Maker of AREPL here! Sorry I didn't see this until recently, hopefully it will still be helpful. To use WSL python in windows vscode you can set your pythonpath to JUST wsl and your pythonoptions to ["python3", "-u"]. When you open it you will get ......
an error. Dang.
The problem is that the python-shell library I use uses path.join which joins the path to the arepl executor file with windows path separators, which doesn't work in WSL.
Instead of trying to run WSL python through windows vscode I suggest installing remote-wsl, opening a WSL vscode, installing the python and arepl extension there, and using that. I tested it and verified that it works.

Issue with dependencies running python file on another PC

I have a python file running perfectly in the IDE.
I want to run it on a different PC without any IDE.
I run the program from the command line: python program.py
Error message: File "program.py", line 8, in
from mpl_finance import candlestick_ohlc
ModuleNotFoundError: No module named 'mpl_finance'
When trying: pip install mpl_finance (or pip install mpl_toolkits)
I get the message: No matching distribution found for mpl_finance (or mpl_toolkits)
There also seems to be a problem with matplotlib backend.
Looking for a solution please.
After many failed paths, here's what worked:
matplotlib.finance is deprecated and it is now mpl_finance.
Create 2 files named mpl_finance.py and setup.py and get their contents from here.
Then from the command-line: python setup.py install
Fixing the backend (this can save you a few days):
If the backend of matplotlib was set in a file original PC (and not in the code). Then you need to do the same on the second PC.
Windows Path: C:\Program Files\Python36\Lib\site-packages\matplotlib\mpl-data\matplotlibrc
Change (probably line 38) to this: backend : Qt5Agg