install mosek.fusion for python in anaconda (ubuntu) - python

I'm trying to use (and therefore install) an optimization package called mosek and more specifically to use it with python on a jupyter notebook.
It's a commercial package but since I'm working in academia, I have a free license.
This issue has been edited thanks to Paul insights.
My goal is to be able to use mosek in python 3.5 through jupyter.
1° My issue:
When I run the following line of code in jupyter notebook :
import mosek.fusion
I have the following error:
import mosek.fusion ---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-9-81543b63d59f> in <module>()
----> 1 import mosek.fusion
ImportError: No module named 'mosek.fusion'
2° What I did :
I first downloaded and installed mosek. I also added my licence in my folder mosek. (I did all the steps described here : http://docs.mosek.com/7.1/toolsinstall/Linux_UNIX_installation_instructions.html and added my academical license as well).
I then tried to run the line of code:
import mosek.fusion which gave an error.
I then tried to run:
import mosek
then I had no error. My conclusion is that mosek is (now, thanks to Paul), properly installed but that fusion module is missing.
I also search for any fusion file or folder in my mosek folder. I did not find any.
Is there a way to get this module fusion from mosek, and even better, is there a way to make it work?
Thank you all!
E.

I believe that it installed it to your .local because you installed with the --user flag. In other words:
python setup.py install --user
Trying running the install without the --user flag. That should install it in your conda environment.
But I'm not sure that is your import problem. Perhaps the fusion module doesn't exist. Try ls-ing what is in this folder /home/edwin/.local/lib/python3.5/site-packages/mosek/. Maybe try from mosek import fusion.

Fusion is not yet available for Python3. It will in the next major release, i.e. MOSEK 8.

The easiest way to install Mosek (for using from Python) is to use the pip installer:
pip install git+http://github.com/MOSEK/Mosek.pip#v7.0.0#egg=mosek
You may also want to set the environement variable for the Mosek lisence explicitly, e.g.
os.environ.setdefault("MOSEKLM_LICENSE_FILE", license) where license is a server address or a file location.
However, Mosek Fusion is not yet available for Python 3

Keep on the MOSEK website. Version 8(beta) soon to be released will support Python 3.5. Also full Anaconda support will soon be available.

Related

Downloaded package ImportError

I have recently installed python 2.17.14 to use a package which I installed in the command prompt with:
python -m pip install packageName
However, whenever I try to use it with a script provided by the package authors, I get Import Errors:
ImportError: cannot import X from YX
ImportError: attempted relative import with no known parent package.
I don't know what I'm doing wrong, as I am really new to Python. Does anyone have any ideas?
The package is called neurodesign and I downloaded the try out script from the official website "neuropowertools.org"
Best,
Max
In case anyone (who is also new to python^^) fails ridiculously at this task as well: I had to manually install all the modules used within this package for it to work as they weren't installed automatically.

Trouble importing python packages using PyCharm

I've been trying to install simple packages for python such as numpy and pandas, and while I am able to install the package manually from the command line using pip as soon as I try to import it PyCharm can't find it. I have manually configured the path, with no luck.
PyCharm can also not find the packages I want to install itself and produces a connection timeout, this could be because I am working from a secure network.
Still pretty new to python and software dev in general, I apologise in advance if I'm being stupid, but no other similar threads are solving the issue.
I am operating on windows 7. The error I get is:
C:\Users\james.alexander\PycharmProjects\Test.py\venv1\Scripts\python.exe C:/Users/james.alexander/PycharmProjects/Test.py/testfile.py
Traceback (most recent call last):
File "C:/Users/james.alexander/PycharmProjects/Test.py/testfile.py", line 1, in <module>
import numpy
ModuleNotFoundError: No module named 'numpy'
I think PyCharm use a virtualenv, installing via pip won't work since it will install the package in your local env.
Check https://www.jetbrains.com/help/pycharm/installing-uninstalling-and-upgrading-packages.html
Try This:
Step 1: Ctrl+Alt+s
Step 2: Look for Project Interpreter Under Project
Step 3: Look for + In the right corner of prompt box.
Step 4: Search and select your required package. And Install button is just below.
First check the Project Interpreter in your pycharm.
File > Settings >Project >Project Interpreter
Check the version of python there (python2 or python3)
And check if you are using any virtual environment
And see what version python you have installed
For python3 you may have to use "pip3 install pkgname"
For python2 use "pip install pkgname"
In PyCharm, you can install modules from within the app. Simply access your preferences, then under 'Project Interpreter', you will find a table containing your installed modules. To install a new one, click the + symbol on the bottom - left, then search for the appropriate package, e.g. numpy. Once you've found it, simply click 'Install Package'. The module is now installed and ready to use!
EDIT: I've just seen that someone else has already posted this answer, sorry about that :)

C++ Error on import CV2 , Tensorflow Ubuntu AMI version 4

Traceback (most recent call last):
File "./src/train.py", line 9, in
import cv2
ImportError: /home/ubuntu/anaconda3/envs/tensorflow_p27/bin/../lib/libstdc++.so.6: version `CXXABI_1.3.8' not found (required by /home/ubuntu/anaconda3/envs/tensorflow_p27/lib/python2.7/site-packages/../../././libicui18n.so.58)
Environment : Source activate tensorflow_p27 ( p3.2xLarge instance )
Hi,
I am trying to run the function train.py which gives me an error on "import CV2".
I did not update the code, or environment or system to avoid any conflicts.
Additionally, I already tried to do a "sudo apt-get upgrade" and the issue still persists.
I performed "conda update --all" and tried again, to no avail.
I am unable to train my models as the system errors at this statement in the command.
The same scripts are working on a P2.xlarge instance without any errors.
I tried StackOverFlow and google search to no avail.
Any help is much appreciated.
Thanks
The conflict happens due to version conflict between the Ubuntu system version, anaconda version and tensorflow_p27 environment version of the libstdc++.so.6 files.
The simplest way to diagnose is
strings /home/ubuntu/anaconda3/envs/tensorflow_p27/bin/../lib/libstdc++.so.6 | grep CXXABI
This should show you the versions of CXXABI available in the TF environment.
Similarly run
strings /usr/local/lib/libstdc++.so.6 | grep CXXABI
and you should see the versions, in this case 1.3.8 available.
The final solution comes from
ln -svf <path-to-system-libstdc++.so.6> <dest-path-to-env-libstdc++.so.6>
This solution worked for me for other lib-XYZABC (e.g. libgomp GOMP-4.0) errors as well. Packaging by anaconda into the environment, independent of tensorflow picking some versions of libraries, is likely the root cause of the problem.
Hope it helps
Thanks

Python packages are imported on terminal but not on IDLE

So I am new in Python. I downloaded Anaconda (and Homebrew) and using Terminal on my Mac I confirmed that, say, Numpy is installed:
pip install numpy
to get as a result
Requirement already satisfied: numpy in ./anaconda/lib/python3.6/site-packages
Then opening Python within Terminal I can indeed import the package. The story is not the same once I open IDLE. So when I open it and try to import, say, Numpy I get the following message:
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
import numpy
ModuleNotFoundError: No module named 'numpy'
I guess there is something I do not know, I assume it is a common rookie problem. Can you help me with this?
Since your IDLE is using Python 3 you should use
pip3 install numpy
to get it installed for the correct Python. If you want to use your default installed Python (2.x) instead, IDLE is located at /usr/bin/. From your terminal you can open it with
/usr/bin/idle
this should have the numpy you installed with pip install numpy
See when you are working with Anaconda it creates its own virtual environment.
Now, If you are new in python on MAC then you might not familiar with Virtual Environment.
I suggest you to download python from the official website www.python.org
or Click here to directly download Python 3.6.2 on your MAC.
Then, Download Pycharm(The Best IDE for Python)
Download the community version for beginner and it is also free.
Pycharm Community Version -> Click Here
And do whatever you want and also must read about Virtualenv
According to me, Pycharm is better then Anaconda's Jupyter Notebook
Wish you good luck and show your creativity in python ! !
Erm... well it appears as though - since you have 2 versions on your computer - that it might be because it imported it into the other file path directory. Now, I've never worked with Mac, but I think if you just specify which pip you want to download from, it might work.
For example, on Windows:
C:\Python34\Scripts\pip.exe install numpy
or if you were doing it for 3.6, you would follow the path to the folder, find pip and install. So, I suggest to install the normal IDLE before any other platform built upon it just because it is easier to import modules and is not as bad to break like yours has.
There can be two issues -
You are using python 2 as a kernel for IDLE, since numpy is installed for python3.6. This will raise an error.
The issue is with anaconda's configuration with IDLE. Anaconda installs numpy in ./anaconda/lib/python3.6/site-packages. If IDLE uses systems default python instead of anaconda's. You will not be able to import numpy.
You can try running this snippet -
import sys
print('\n'.join(sys.path))
to track the location of python exactly.
One of the workaround that I can think of is -
create a virtual environment using anaconda. Something like
conda create -n py352 python=3.5.2 anaconda
and then fire IDLE from your terminal. Though I am not entirely sure, if this works for mac. If it doesn't, let me know the output of -
import sys
print('\n'.join(sys.path))

ImportError: No module named twisted.persisted.styles

From IDLE, I tried to run a script with a newly installed scrapy 1.0.3.
I'm using a script from a friend whom it worked for (but on Windows, I'm on a Mac).
From the import of scrapy on the first line, I get this error when running the program:
ImportError: No module named twisted.persisted.styles
The whole script, if it's helpful, points to this:
Traceback (most recent call last):
File "/Users/eliasfong/tutorial/tutorial/spiders/medspider.py", line 1, in <module>
import scrapy
File "/Library/Python/2.7/site-packages/scrapy/__init__.py", line 27, in <module>
from . import _monkeypatches
File "/Library/Python/2.7/site-packages/scrapy/_monkeypatches.py", line 20, in <module>
import twisted.persisted.styles # NOQA
ImportError: No module named twisted.persisted.styles
Any suggestions on how to tackle this problem?
Just try to force the update of twisted :
pip install twisted --upgrade
That works for me with python3.4 and Scrapy==1.1.0rc1
Either twisted is installed on your mac (I highly doubt it since it's not a standard library) and for whatever reason the IDE (i'm assuming that's what you mean since you typed "idle") or the terminal you are in doesn't have your updated environment variables, meaning it doesn't understand where your default python libraries are (again I highly doubt it), or you simple do not have twisted installed on your mac. If it's not installed you have a couple of options:
The easiest way to install a python package is through pip.
If that not an option you can try homebrew which is another package manager for macs. It offers an easy way to install packages correctly.
If that still is not an option for you or you simply don't want to attempt that you can download twisted directly from here (the .bz2 since you're on a mac), click on it and it should unzip it for you. Then just run setup.py and it should install it in the correct location on your mac.
If that still doesn't work and you have decent knowledge of unix. Use the "locate" command on the terminal and find out where your dist-packages directory is and put the source for twisted in there directly and then attempt to import twisted in your IDE or in the python interpreter to verify that it is installed.
note: If you're still having problems after it is installed trying restarting your IDE or messing with some setting to make sure your IDE has the right environment and python path. Hope that helps!
It could be related to having installed Python without bzip2. I had the same error and this helped me, see the accepted answer here:
Installing Twisted through pip broken on one server
Had this exact thing on FreeBSD. Solution (as root/sudo):
chmod -R go+rX /usr/local/lib/python2.7/site-packages
Some directory permissions weren't set up right on install.

Categories