Cannot import GLPK in Anaconda - anaconda

I searched a lot an answer to my problem but wasn't able to find a fix.
I'm running anaconda.
I installed glpk with from conda-forge with the command:
conda install -c conda-forge glpk
The installation worked fine but then in my notebook, I've got an error message when I try to import the module :
ModuleNotFoundError: No module named 'glpk'
I had no problem to install and import other packages.
Any ideas?
Thank you very much in advance

The files installed by
conda install -c conda-forge glpk
can be found at https://anaconda.org/conda-forge/glpk/files. Looking at the archives only the GLPK C library is installed and no Python binding or package.
One of the packages that can call the GLPK library from Python is Pulp (https://anaconda.org/conda-forge/pulp).

I'm conda/windows user. I never could import it directly, but based on this SO answer I could make work a library that consume it (pypsa)
Basically, download the library (is in sourceforge) and add it to windows system path
Hope this help to somebody googling this issue. Bests

Related

install "sub package" Jupyter Notebook

I am struggling to install packages, and "sub-packages" in Jupyter Notebook; I suspect I am missing some of the basic concepts around installing packages.
I understand that to install a package within the notebook I use
! pip install --user <package>
What I don't understand is how to install a "sub-package" (feel free to advise what the correct terminology is) such as below.
from nltk.tagger import *
Here is the original script that this comes from:
If i try :
!pip install nltk.tagger
I get the following error information / error
Collecting nltk.tagger
Could not find a version that satisfies the requirement nltk.tagger (from versions: ) No matching distribution found for nltk.tagger
So my first question is. How do I install this nltk.tagger subpackage? Also if tagger is a sub-package of NLTK, how come it isn't installed when I do a pip install NLTK?
Although the error mentions a version, searching online I can't find a reference even to the subpackage "tagger". Any advice or links explaining this would be appreciated.
if you pip inslall nltk, the subpackage nltk.tagger, and other dependencies will be installed too.
This is generally true for all packages.

Clean install of Scientific Python without reformatting the disk

1st, the Disclaimer: I looked at numerous questions here, there is question about uninstalling all pip–installed, uninstalling matplotlib, moving to 3.5 from 2.7, –– but I didn't find an answer to my specific problem. Sorry if I didn't look hard enough.
Basically, my problem is I have a mess of different packages installed by different means at different times. Manifestations of this are:
1) I can import numpy from python but not from Jupyter notebook:
------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-5a0bd626bb1d> in <module>()
----> 1 import numpy
ImportError: No module named numpy
2) I cannot import nltk:
...
File "numpy.pxd", line 155, in init sklearn.utils.murmurhash (sklearn/utils/murmurhash.c:5029)
ValueError: numpy.dtype has the wrong size, try recompiling
likely many more.
I recently uninstalled jupyter and anaconda, installed anaconda again, - this didn't help.
I cannot uninstall numpy / scipy , although I can use them (?!?):
>:~%python -c 'from numpy.random import rand; print rand()'
0.946167984715
>:~%pip uninstall numpy
Cannot uninstall requirement numpy, not installed
I have two versions of Python:
2.7.11 under /usr/local/bin/ pointing to /usr/local/Cellar/python/2.7.11/bin/python
2.7.10 under /usr/bin/ pointing to
/System/Library/Frameworks/Python.framework/Versions
-- although the default is 2.7.10 (numpy works with it), and I think 2.7.11 was added by Anaconda (incorrectly, because it doesn't see numpy).
Yesterday I uninstalled everything I could think of, then upgraded to a new version of Mac OS (10.12.2 Sierra), and then re-installed anaconda – in vain.
I am close to reformatting the disk and starting from scratch.
Is there a better option?
Thank you! and sorry for so many details.
Not sure exactly on a MAC but these are the things to try on windows and it is probably similar on MAC.
Start with a clean install of anaconda then try "where python" and "where jupyter" (it is "which" instead of "where" on linux). This tells you where it is looking for the executables. Both should be subfolders of anaconda. If they are not check your PATH variable.
Now start python or jupyter; import sys and try sys.path. That tells you where python is looking for stuff. It should look only in anaconda sub folders.

Import NLTK : no module NLTK corpus

I have installed NLTK. Here's an image of the installation log.
When i use import nltk i get an error:
"No module named NLTK.corpus"
Here is a screenshot.
What could be the cause?
I think I had the same problem. So, downloading all the packages at once (since question didn't specify).
Start python and then import the packages, exit python and upgrade nltk. Modify the 'all' to download a specific corpus. Took me awhile to complete the 'all' download, I separately downloaded framenet_v15 and restarted the 'all' after. Upgrade nltk when the download is complete.
$ python
>>>import nltk
>>>nltk.download('all')
exit python
$ pip install --upgrade nltk
To fix this, you should rename your file to something else, say nltkXXX.py. Also make sure to remove "nltk.pyc" from your directory if it exists, since this will also be loaded (it's the byte compiled version of your code). After that, it should work fine.
If you are using the latest version of python, then try installing nltk using pip and the wheel downloaded from here:
http://www.lfd.uci.edu/~gohlke/pythonlibs/
Then in command prompt, use the command:
pip3 install
This should install nltk correctly.
After that check the installation in python using the command:
import nltk
and download the nltk data required using:
nltk.download()
If you find (Import NLTK : no module NLTK corpus) that type of error .
Make sure your saved file not be the name like (nltk.py).
so just rename your file name (like rename nltk.py to example.py ) or something else:
I hope it will help you.
thanks
If you has using PyCharm IDE, you should have install NLTK from the IDE's own tools [File -> Settings -> Projetct Interpreter -> Install (button '+') -> Install Package].

Installing numpy on mac with pip: "requirements already satisfied" but "No module numpy"

I have python2.7.8 on mac, things I did:
sudo easy_install pip - worked.
pip install numpy:
Requirement already satisfied (use --upgrade to upgrade): numpy in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
I also did "pip upgrade numpy" - no luck. What's wrong?
Your problem is a conflict of different Python versions.
I would recommend installing Python and all the packages, such as numpy, scipy, matplotlib, pandas, etc via Brew
See this tutorial: https://github.com/Homebrew/homebrew/blob/master/share/doc/homebrew/Homebrew-and-Python.md
You can verify which Python you're running with which python or which python3 in Terminal.
This solution is more flexible and cleaner in my opinion than using Conda/Miniconda. However it is also a bit more lengthy to install, as you need to have Xcode, devtools installed to build everything
Could it be that you have multiple versions of python installed? What happens if you run python using the full path like this:
$ /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2
instead of just python2?
In my experience on Mac (and other OS too) it is best to go with Anaconda / Miniconda. This is especially true for packages like NumPy and others from scientific stack.
While Anaconda is a full-blown distribution with about 200 packages, Miniconda is just Python with a few basic libraries. The big advantage is that all packages install as binary. Further, it makes it very simple and stable to install multiple Python versions side by side. For example:
conda create -n py27 python=2.7
creates a new environment with Python 2.7. Activate with:
source activate py27
Now:
conda install numpy
installs NumPy cleanly.
You can do the same for Python 3.5 and switch between environments with source activate.
After jumping from one stackoverflow answer to another I found the solution!
my problems were:
numpy at different location( actually at right, expected-to-be location). It was the IDLE that looks for its own default folder where python2.7 installed.
I checked that my numpy is working like this, run this script to check it is working:
import os
import sys
import pygame
sys.path.insert(0, '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python')
import numpy
pygame.init()
print "( using __version__): " + numpy.__version__
print numpy.version.version
user_paths = os.environ['PYTHONPATH']
print(user_paths)
sys.path insertion adds additional path to IDLE, so it knows where to look for numpy.
Then I check if numpy truly imported - i just print its version. Right now it is 1.8.0rc.
I want to find a way to avoid using this syspath insertion all the time.
So far so good - for now.
I had a similiar problem with numpy. However, it was resolved by choosing the right environment. If you are using VScode, open the command palette (ctrl+shift+p) and type
Python: Select Interpreter.
From there, try choosing the right virtual environment/Interpreter.

'Error importing Gtk module: No module named repository' with graph_tool

Hello stack community!
I'm not sure if my question is graph-tool related or gtk-related, but maybe both. Moreover, sorry if what I did while trying to solve it is plain stupid, I'm not a programmer by formal education, so I know just as much as I could find by google and comprehend.
Here is the problem:
After I brew install graph-tool, launch python and try to import graph_tool.all I get the following error:
/usr/local/lib/python2.7/site-packages/graph_tool/draw/cairo_draw.py:1318: RuntimeWarning: Error importing Gtk module: No module named repository; GTK+ drawing will not work.
Previously I was sure that if import pygtk; pygtk.require('2.0'); import gtk works, that means the error is a graph-tool issue, but that don't have to be the case since graph-tool might use gtk (3??) and GObject (right?) and the upper checks for gtk2 and pygtk ( This question led me to this thought ).
I tried reinstalling gtk, GObject and all dependencies. Wipe all brew-related and brew itself and then reinstall everything (as in here). Still same error appears. I also tried to unlink everything from brew and link it again just to be sure, but this does not change anything either.
What else did I check:
I'm running MAC OS X Version 10.10.3, homebrew-installed python 2.7.10 (python --version returns Python 2.7.10 which is the one installed by brew; which python points to /usr/local/bin/python). brew info graph-tool shows that all requirements of it are there (even the optional ones). GTK 2.24.28, GTK+3 3.16.4, PyGobject 2.28.6, GObject-introspection 2.28.6, Cairo 1.14.2, Py2Cairo 1.10.0, pango 1.36.8, XQuartz 2.7.7 etc are installed, dependencies of those are fine as well. gi 1.2 is installed (via pip), gi.repository is indeed not there. I am aware of this question, but I have PyGObjects installed.
I also read this question and the reply, but none of this solves my problem as far as I can judge.
I've spend two days looking for the solution, so any help is appreciated.
It's seem to be a cairo dependency issue.
As you may see here, graph-tool package require a lot of depencies (numpy, gfortran, scipy, freetype, libpng, matplotlib, boost, cgal, graphviz, cairo, cairomm, py2cairo)
In your case you may probably solve the issue with a clean reinstall of "cairo".
Try those commands:
brew install cairo
brew install cairomm
brew install py2cairo
If "brew" ask you to run command or install other packages, do it !
(We assume here that "brew" is properly installed)
Best regards
I've faced the same issue (with a slight difference on the line number):
>>> from graph_tool.all import *
/usr/local/lib/python2.7/site-packages/graph_tool/draw/cairo_draw.py:1499: RuntimeWarning: Error importing Gtk module: No module named gi; GTK+ drawing will not work.
warnings.warn(msg, RuntimeWarning)
I know it's a relatively old question but wanted to share how I did it. You said you tried reinstalling GObject, but that is what made it work here.
I followed the installing instructions
brew install pygobject3 --with-python#2 gtk+3
which said gtk+3 and pygobject3 were already installed. Then I ran:
brew reinstall gtk+3
and
brew upgrade pygobject3
which made the import work.

Resources