cannot use ortools from Google - python-2.7

I installed or tools onto a macbook pro running Mavericks (10.9.5) as per these directions
I did initially get the error described here: can't install or-tools on mac 10.10
and followed the recommendation using easy_install. yes I did get the error they describe but it seemed that or tools installed properly. Issuing
import ortools
at the python prompt did not generate an error.
Then I went to try one of the examples google provided (see first link above) and get this error:
Traceback (most recent call last):
File "examples/golomb8.py", line 26, in <module>
from google.apputils import app
ImportError: No module named google.apputils
Obviously I missed something. Can someone enlighten me??

Your issue here is that the google.apputils module is separate from ortools and needs to be installed separately. You can check ortools is installed by running some other examples in the Google provided repo such as python examples/map.py , or the example in this repo and ensuring python optimize.py results in the expected NBA lineup (such was my original reason for looking into ortools :-)).

Related

Anaconda error after install on Windows

I want to install Anaconda on my x64 Windows machine, and I downloaded the Python 2.7 version 64-bit installer. The installation process looks good.
Then I installed pip with choco and installed several packages like zbar,
however, when I want to try to launch Anaconda, I entered conda in Powershell, this is what I got:
Traceback (most recent call last):
File "C:\Users\Ruiyang\Anaconda2\Scripts\conda-script.py", line 3, in <module>
import conda.cli
ImportError: No module named conda.cli
Does anyone knows how to fix this?
add anaconda's bin directory to path.
set path=whatever\anaconda\bin;path;
This issue is related to the path variable setting. Quoting from another SO post:
fire up your interpreter and add this line: export PATH=/Users/add
your username here/anaconda/bin:$PATH
Now type python into the interpreter and you will see Anaconda 1.8.0
or whatever version you have. You will have to do this each time you
start a new interpreter.
Also, note that this might occur when the user name in the path on windows contains a space character. Taken from here.
Though #devautor's method doesn't work for me, a comment in his reference shows me the correct answer:
Unset both PYTHONPATH and PYTHONHOME, then my problem is solved.

Spyder won't launch on Windows using 32 bit Anaconda

I am trying to use spyder on windows 10 using python 2.7 32 bit version of anaconda. I am unable to open spyder through the anaconda interface, through a command prompt or through the spyder.exe. I get the following error message in the command prompt:
Traceback (most recent call last):
File "C:\Users\Brendan\Anaconda2\Scripts\spyder-script.py", line 5, in <module>
sys.exit(spyder.app.start.main())
File "C:\Users\Brendan\Anaconda2\lib\site-packages\spyder\app\start.py", line 103, in main
from spyder.app import mainwindow
File "C:\Users\Brendan\Anaconda2\lib\site-packages\spyder\app\mainwindow.py", line 92, in <module>
from qtpy import QtWebEngineWidgets # analysis:ignore
File "C:\Users\Brendan\Anaconda2\lib\site-packages\qtpy\QtWebEngineWidgets.py", line 26, in <module>
from PyQt5.QtWebKitWidgets import QWebPage as QWebEnginePage
ImportError: DLL load failed: The specified procedure could not be found.
Note that I previously had the 64 bit version of anaconda with python 2.7 and spyder worked fine. I have had this problem ever since I uninstalled the 64 bit version and installed the 32 bit version. I also deleted all of the .anaconda, .spyder, etc. folders before reinstalling.
I have also tried most of the suggestions found here: Python Spyder reset here: ImportError: DLL load failed: The specified procedure could not be found. Python and here: Can no Longer open Spyder IDE for Python Programming, including updating all packages
Any insight would be appreciated as I am relatively new to using python and I do not understand the error message being thrown. I am able to locate the QtWebKitWidgets file in the PyQt5 folder.
I know this is old, but I was having the same problem and found the solution! I had an old Anaconda2 64-bit version installed on my computer (Windows 10 x64), but needed to switch to 32-bit Python for a project. I uninstalled the 64-bit version and installed the 32-bit version and couldn't open Anaconda Navigator, Spyder, etc and got a similar error message to above.
The solution can be found here. In short, you need to reinstall a specific PyQt version conda install pyqt=4.10.4. After this, Spyder opened without issue.
I know this is an old thread, but the following worked for me when my spyder IDE wouldn't load.
The problem was that the status of spyder was still running so wouldn't open. To fix this you need to look for a directory called .spyder-py3 in your Users\ directory, then find a file called "spyder.lock". Underneath this file there were a bunch of files called "spyder.lock.a_bunch_of_numbers.newlink". Once I removed all the spyder lock files the Spyder IDE opened.

Spatialite with Python 2 and 3

I am attempting to use spatialite with both Python 2 and 3 on Windows 7.
Rather than try to patch pyspatialite for Python 3, I decided to use the load_extension approach with sqlite3 Python built-in package, similar to how is done here: Sqlite load_extension fail for spatialite in Python and here: Use spatialite extension for SQLite on Windows.
But, on the official (C)Python 2.7 installer, the load_extension was disabled for an issue related to MacOS. This is not with the counterpart for Python 3.4. Furthermore, both installers are built without SQLITE_ENABLE_RTREE=1 (that I'd also like to have).
At first, for Python 2.7, a workaround was to build pysqlite tweaking the setup files to have both R*Tree and extensions. This way does not work for Python 3, since it does not seem to be supported by the current setup.py. From my understand, this is because the package moved to the core Python repository: https://github.com/ghaering/pysqlite/issues/72#issuecomment-94319589
My current solution was to re-build both Python 2.7 and 3.4 with required settings for sqlite3 package. It worked, and I was able to load spatialite as an extension and to create R*Tree.
Does it exist an alternative simpler solution? Did somebody find an alternative solution by working on the setup.py of pyspatialite or pysqlite?
There is an easier solution that I just got working. I'm running Windows 10 with Python 3.5 using the default sqlite3 package, and Spatialite 4.3.
This is how I did it:
Let start with a simple program that loads the spatialite extension (which we haven't installed yet):
import sqlite3
with sqlite3.connect(":memory:") as conn:
conn.enable_load_extension(True)
conn.load_extension("mod_spatialite")
If you run this program you get:
C:\> python test.py
Traceback (most recent call last):
File "test2.py", line 5, in <module>
conn.load_extension("mod_spatialite")
sqlite3.OperationalError: The specified module could not be found.
That means it can't find the mod_spatialite extension. Let's download it from the Spatialite website. At the bottom there's links to "MS Windows binaries". I picked the x86 version, current stable version, and downloaded the file called mod_spatialite-4.3.0a-win-x86.7z. Unzipping that file to the same directory your test.py file is in, and running the program now produces no errors (ie. it works!):
C:\> python test.py
C:\>

pyinstaller single exe of program which uses google api client lib

I have a python program which I've successfully packaged up as a single exe using pyinstaller in the past. Recently I added new features which make use of the google api python client ( https://developers.google.com/api-client-library/python/ ). I've attempted to make a new single exe package of the new version and it fails to run.
I enable debugging and the console and initially the issue was that it hadn't picked up the oauth lib. I fixed that by adding the following to my spec file:
hiddenimports=['googleapiclient', 'apiclient']
When I build I can see this:
53092 INFO: Hidden import 'googleapiclient' has been found otherwise
53093 INFO: Hidden import 'apiclient' has been found otherwise
However, now when I run the rebuilt exe I get the following error before it exits:
pkg_resources.DistributionNotFound: google-api-python-client
I can't see any reference to that and I'm not sure how to force it to be packaged up with the exe.
I figure I can't be the only person to have ever wanted to package up a python program that makes use of the google api, but I failed to find any help during a lot of time with my friend google...
Any tips?
Many People Have same question but I can't find any answer
Try This way
find site package of your project
enter the Pyinstaller/hooks and find hokk-google.api_core.py
add line ( edit line ) datas += copy_metadata('google-api-python-client')
example
from PyInstaller.utils.hooks import copy_metadata
datas = copy_metadata('google-api-core')
datas += copy_metadata('google-api-python-client')
excute pyinstaller hidden-import google-api-python-client
pyinstaller --hidden-import google-api-python-client
you can avoid error
pkg_resources.DistributionNotFound: google-api-python-client
I was able to dig deeper into this issue after I switched from using pip to easy_install to install the google-api-python-client package. Manually installing the egg file gave me a much neater way of testing.
I then started building using pyinstaller with out the --onefile option, this way I was able to start messing with the egg file that was packaged up with my program. Eventually I found out that my problem was stemming from the fact I'm making use of Pandas and the Google API.
Here's the relevant Pandas bug on github.
To solve the problem I had to update my version of Pandas.
I did find that if I moved to the most recent version of Pandas (1.6.0) I ran into a new issue because it imports dateutil and it causes problems looking for the zoneinfo file. I've landed on Pandas 1.5.1 and it is all working.
You can also add site-packages using:
--add-data "path_to_your_package:package_name(e.g googleapiclient)"

Installing anaconda to use with windows

I am lost in the installation process of installing anaconda on windows.
I've installed the windows 32bit package (I'm running windows 7 x64)
I have anaconda in the start menu and I can open the python console and use scipy.stats.t.interval(), the function I am interested in.
However, how do I go about including this in another python program? I think it's something like adding it to the path. For instance, I have the scipy.stats.t.interval() function call in my other python file which I run through cygwin via python myscript.py. However it returns the error:
from scipy.stats import t
ImportError: No module named scipy.stats
I think it might be a change of path / add to path issue, but I'm not sure how to fix it :/. While I try to fix it, I figure I will post for help here.
well you might have two installations of python, one inside the anaconda package, and other which you might have installed earlier. try doing :
which python
from CygWin console.
If it returns:
/usr/bin
then it is definitely a add-to-path problem.
to fix it for CygWin,
you have to add the python installation from anaconda to the path.
try this fromn CygWin:
PATH=path-where-anaconda-is-installed/anaconda/bin:$PATH
and then doing:
which python
should give you:
/path-to-anaconda/anaconda/bin
and then it will work.
Cheers