Unable to import matlab.engine in python - import

import matlab.engine
In my case, with MATLAB R2014a, I got the following error message:
ModuleNotFoundError: No module named 'matlab'
and this path "matlabroot\extern\engines\python" is not present

"matlabroot" is not part of the path name. It needs to be replaced with the name of the MATLAB root directory. Typically that's, "C:\Program Files\MATLAB\20???"
Where ??? is replaced by your MATLAB version number.
So, open the command prompt with administrative privileges.
cd "C:\Program Files\MATLAB\2014a\extern\engines\python"
python setup.py install
If you don't have admin privileges, you can use this command to name alternative directories for setup.py to use:
python setup.py build --build-base="builddir" install --prefix="installdir"
Good luck!

Related

How to fix 'zsh: command not found: pytest'?

I have python3 and pip3 installed. I also install pytest but when I enter the command pytest, it does not work. It shows me the following:
<zsh: command not found: pytest>
How do I fix this please?
You need to specify the location of the pytest executable—the program that executes pytest—to your computer in order to use the pytest command.
You can do this by adding the directory path where the pytest executable is located to your computer's list of locations it should search for applications.
The PATH environment variable is the name given to this list.
You may use your computer's settings to update the PATH environment variable or you can execute a program in the terminal to add the path of the directory containing the pytest executable to it.
Your computer should then will be able to locate and launch pytest once the PATH environment variable has the path to the directory containing the pytest executable.

pyrcc5: No such file or directory

I want to install labelImg for mac OS in python 3.7. here is the repo: https://github.com/tzutalin/labelImg
I have installed previous modules via 'pip3 install pyqt5 lxml' successfully. Cloned the repo, entered the folder 'labelImg', but only 'make qt5py3' does not work..
but when I execute 'make qt5py3', i get the error
pyrcc5 -o libs/resources.py resources.qrc
make: pyrcc5: No such file or directory
make: *** [qt5py3] Error 1
What can I do here? What might have caused the issue?
-find 'pyrcc5' under python bin, and copy 'path'
-under labelImg find 'Makefile' and edit
-change line
qt5py3: pyrcc5 to qt5py3: 'copied path'/pyrcc5
and save
-and
make qt5py3
python labelImg.py
should works.
I had the same issues as the OP, but with Python 3.6.11. In addition, I got ModuleNotFoundErrors for pyqt5 and libxml2, even though brew confirmed they were both installed. Also, I was trying to install in a virtual environment set up using pyenv.
What finally worked for me was:
1) use global env, not virtual
2) use pip (not pip3) to install pyqt5 and lxml
3) change the makefile as #zippo suggested
After I did that, I was able to get labelImg to start by running:
python labelImg.py

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

ImportError: dynamic module does not define module export function (PyInit_cv2)

When I try to import cv2 in IPython , I am getting this error-
ImportError: dynamic module does not define module export function (PyInit_cv2)
I have opencv 3.0, ubuntu 14.04, python 3.4.
I searched online but couldn't get any answer.
Python3 libraries usually can be found in:
/usr/lib/python3/dist-packages
I found out that the library cv2.cpython-34m.so is needed for Python3.4.
But this file wasn't be contained in my default library directory.
In my environment, this library was stored in /usr/local/lib/python3.4/dist-packages/
So I created a symbolic link.
Try it with:
cd /usr/lib/python3/dist-packages
sudo ln -s /usr/local/lib/python3.4/dist-packages/cv2.cpython-34m.so
python3
>>> import cv2
I hope, this helps you
In my case, I was using opencv library for python2 in python3.
Check your PYTHONPATH by typing
echo $PYTHONPATH
and see there is correct path for python3.
$ echo $PYTHONPATH
:/usr/local/lib/python3.4/site-packages
I define PYTHONPATH at the end of ~/.bashrc file. Modify it if you are loading python2's library.
After source ~/.bashrc or restart terminal, check PYTHONPATH again
It solves my problem.

mkvirtualenv: Too many levels of symbolic links

I am running virtualenv burrito and getting an error that there are too many levels of symbolic links. I have no idea what that means.
mkvirtualenv --python /usr/local/bin/Python3 mantis
Error:
Running virtualenv with interpreter /usr/local/bin/Python3
Using base prefix '/Library/Frameworks/Python.framework/Versions/3.4'
New python executable in mantis/bin/Python3
Also creating executable in mantis/bin/python
Traceback (most recent call last):
File "/Users/croberts/.venvburrito/lib/python2.7/site-packages/virtualenv.py", line 2352, in <module>
main()
File "/Users/croberts/.venvburrito/lib/python2.7/site-packages/virtualenv.py", line 825, in main
symlink=options.symlink)
File "/Users/croberts/.venvburrito/lib/python2.7/site-packages/virtualenv.py", line 985, in create_environment
site_packages=site_packages, clear=clear, symlink=symlink))
File "/Users/croberts/.venvburrito/lib/python2.7/site-packages/virtualenv.py", line 1439, in install_python
raise e
File "/Users/croberts/.venvburrito/lib/python2.7/site-packages/virtualenv.py", line 1431, in install_python
stdout=subprocess.PIPE)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/subprocess.py", line 859, in __init__
restore_signals, start_new_session)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/subprocess.py", line 1457, in _execute_child
raise child_exception_type(errno_num, err_msg)
OSError: [Errno 62] Too many levels of symbolic links
I was getting this error before and solved it by doing Python3.4 instead of Python3. Now it won't work no matter which python I try to use. Even if I try to use the default (2.7)
Strangely, I ran into this when I tried to create a virtualenv with a name that already existed. Solution to remove the old and create a new one:
rmvirtualenv old-one
mkvirtualenv new-one
I had the same problem on OSX.
I got rid of it after:
1. removing env folder
2. removing __pycache__ folder
The reason this wasn't working was because I was capitalizing Python. As soon as I did it using python3 instead of Python3 I stopped getting trouble.
I'm using a mac and I solved this by rm the virtual env that is named the same as you are trying to create. Specifically, I rm the folder within Users/user_name/.virtualenvs/. Then the create worked.
I'm not sure why but using
python3 -m venv venv
instead of
virtualenv -p python3 venv
and then activating the venv or setting the paths manually, something like this
export PYTHONPATH=.:\$PYTHONPATH
VIRTUAL_ENV=`pwd`/venv
export VIRTUAL_ENV
PATH="\$VIRTUAL_ENV/bin:\$PATH"
export PATH
worked for me.
I tried to do some quick searching of the different between virtualenv and python3 -m venv module...but didn't find anything.
I came across it after I had built my freshest environment. Because it has been interrupted by myself while it was building the new one. Then I noticed that virtualenvwrapper already created a new environment folder underneath the environment directory but it has not been accomplished properly. Hence, I deleted the lastest environment folder and retried to install same environment. It fixed!
I had the same problem in raspberry pi during open cv installation.
I solve my problem by using below method.
Go to /home/pi
ls -all and check weather .virtualenvs is there or not
if it is there remove it by
rm -r .virtualenvs
File "/Users/croberts/? seems you're using Windows. Consider using 'virtualenvwrapper-win'. The latest version is 1.2.0 which support python 2 up to 3.4. I've used it without any problems. If you use several versions of python on your computer, you can switch between them using 'pywin'.
For making new virtualenv:
C:\Users\your_directory>mkvirtualenv neo
Using base prefix 'C:\\Python34'
New python executable in neo\Scripts\python.exe
Installing setuptools, pip...done.
For view existing virtualenv:
C:\Users\your_directory>lsvirtualenv
dir /b /ad "C:\Users\your_directory"
=========================================================================
env0
env1
env2
neo