Use Python within MATLAB environment (2019a) - python

I have 2019a version of MATLAB and I am trying to explore the usage of Python from within MATLAB environment. I have Anaconda 3 installed for Python. In MATLAB, when I issue, pyenv, I get 'Undefined function or variable 'pyenv''
The documentation says that Python is supported, but I am not sure why this doesn't work. Any suggestions?
Edit:
Thanks. Solution is to use pyversion, but also set the path with the entire path
pyversion 'C:\Users\newuser\AppData\Local\Continuum\anaconda3\python.exe';

pyenv was introduced in R2019b. In R2019a and older, you need to use the older pyversion function.

Related

How install Python 3.8.3(Global) and a Python 3.7.3(local)?

I need Python 3.8.3 (Global) for a project, the latest version and Python 3.7.3 (Local) to use pyautogui, to convert a .py file to .exe, could someone please tell you how to do this, or if there is any alternative. Thank you very much for your attention and cooperation.
My suggestion is to use Conda and create a new environment with a specific python version.
https://docs.conda.io/projects/conda/en/latest/user-guide/install/

Creating a pandas.Series in the latest version of python pandas doesn't work in Matlab

I am calling several python libraries in Matlab and am now having trouble using the latest version of pandas (ver 0.23.x) https://pandas.pydata.org/ . Conversely, pandas 0.22.x works fine.
Note that the problem doesn't exist in python.
To reproduce:
% set desired python environment
pyversion(pypath)
% try to create a pandas series
py.pandas.Series(1)
Error using py.pandas.Series
Class 'py.pandas.core.series.Series' is not allowed to define a 'cat' method.
Has anyone experienced this?
I noticed that pandas has moved the CategoricalAccessor (which 'cat' refers to) from pandas.core.series.CategoricalAccessor to pandas.core.arrays.categorical.CategoricalAccessor. Maybe this is related?
Any help on this would be appreciated.
I can reproduce this on R2018b with python 3.6.6 and pandas 0.23.4, on Win10 x64.
What you suggest is very likely related, since pandas' cat likely interferes with MATLAB's cat which is used for concatenation.
I would advise you to create a new virtual environment, with the correct version of pandas, and have MATLAB use that (via the pyversion command). After all, this is exactly what virtual environments are for. See also this documentation article.

Python doesn't see a library graph_tool

I have installed the "graph-tool" library. I used am instruction from official site https://git.skewed.de/count0/graph-tool/wikis/installation-instructions (the option "Installation via package managers". I use Anaconda distributive (I included it in the PATH) instead of system version of Python. And there is a problem... When I use system python it sees this library but my Anaconda doesn't...
What should I do that my Anaconda will see it?
Thank you.
On Ubuntu you will, as far as I know, have to compile graph-tool from scratch in order for it to work correctly when using anaconda python.

How do I fix there is no such module error in python 2.6?

I've been using python 2.7 and after installation of python 2.7. All of the scripts have run successfully, but suddenly today, when I run python, it is recognized with python 2.6, so for one of the python packages I get the following error:
/Library/Frameworks/Python.framework/Versions/2.6/Resources/Python.app/Contents/MacOS/Python:
No module named htseq-count
i am not sure why it happens. The path environment variable for python is set to:
PATH="/Library/Frameworks/Python.framework/Versions/2.7/Resources/bin:${PATH}" export PATH
How do I fix this error?
If your code relies on a particular version of Python, you should specify python2.7 or python2.6 instead of just python.
If this "suddenly" happened it's possible that installing some other software modified your $PATH so that the old version of Python now has priority (it's possible for multiple versions to be on your $PATH; it uses the first one it finds).
If you move these two lines to the bottom of the file they're in (maybe ~/.profile) it may correct this.
PATH="/Library/Frameworks/Python.framework/Versions/2.7/Resources/bin:${PATH}"
export PATH
You can type which python in Terminal you can see what binary it finds when looking for python on your $PATH.
If you don't mind using Python 2.6, you can probably install the missing package by typing this in your terminal:
easy_install-2.6 htseq
I think you are applying different python version to be used.
type
which python
under your control.
see which python you are using, you should config the one using python 2.7
python --version

Python 2.7.1 can't see Twisted

I have a new MacBook Pro running OS X 10.6.6 / Snow Leopard -- which ships with Python 2.6, although I have installed 2.7.1
Unfortunately, this doesn't seem to see the Twisted install in the 2.6/Extras/lib/python/twisted directory, as I find I'm unable to import modules that I can see are present in that directory.
"which python" returns "/Library/Frameworks/Python.framework/Versions/2.7/bin/python"
and running python returns the same: "Python 2.7.1 (r271:86882M, Nov 30 2010, 10:35:34)"
I have added the twisted directory (absolute) to sys.path, and I have added it to .bash_profile, which now consists of the following:
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
PATH=$PATH:/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/twisted
export PATH
Any ideas how I can get 2.7.1 to see the Twisted install? Or am I trying to do something that just can't be done?
thanks.
You'll need to install Twisted into your Python 2.7 installation somehow. The "2.6" in that path should be a hint that you shouldn't be trying to tell Python 2.7 about it. Among other things:
Extension modules are not compatible between python versions. You may get a segfault if you try to use them.
Bytecode formats are not compatible between python versions. Python will fall back to parsing '.py' files, which is slower.
If you're using an operating system that ships with Python 2.6, there is a good chance that the version of Twisted included is not compatible with Python 2.7, since Python 2.7 may not have been out yet when it was released.
You'll have to install twisted using python 2.7.
Also, python doesn't look up what's in the PATH variable for imports, it looks in PYTHONPATH. But just putting your python 2.6 folder in your pythonpath isn't a very good solution.
Create an environment using virtualenv.
Install Twisted in your newly created environment using pip.
You need to set up an environment for your new Python 2.7 or use the OS installed 2.6.
OS X ships with NumPy for example, but your new Python 2.7 will not 'see' it.
The best solution (IMHO) is this:
o Don't change the OS default Python AT ALL!
o Install Python 2.7, 3.0 as you wish with the system Python first in the path
o Use virtualenv to set up a personal Python environment -- a sandbox. Install twisted into that.
o Install libraries into the environment you are going to use for the job. Might mean duplicates.
o Use your shebang to execute the proper Python

Categories

Resources