import ortools in mac - python-3.x

I am trying to run some code using ortools on a python environment. I did not have troubles on a windows machine but I am having problems on mac (10.12.6). if in my virtual environment I run
pip freeze
or
conda list
ortools appears in my list of installed packages. But if I try to use it
ipython
from ortools.linear_solver import pywrapplp
I get an error saying that there's no module named ortools. If I go to
mac/anaconda3/envs/nameenv/lib/python3.6/site-packages I do have a folder called ortools with some python files including pywrapplp. Do you know what I am doing wrong ?
EDIT
following request from coments:
import os
os.getcwd()
returns '/Users/imac'
which ipython
/anaconda3/bin/ipython
Installing ortools is a bit of a headache. It was some days ago, I think I finally made it with
easy_install ortools
I think it is a problem with the path. I guess because I did not install it with conda it does not find the package. I got around writting:
sys.path.append('/anaconda3/envs/env_name/lib/python3.6/site-packages/')
at the begining of my ipynb. That way I can run ortools.

You could have several python interpreter installed (python2 and python3)
So if you want to use it with ipython, which seems to be bind on python3 in your case.
First check if you have pypi package ortools installed
ipython -m pip show ortools
If you got an error it means the package is not installed.
so you can easily install it using:
ipython -m pip install --user ortools
note: We provide Pypi ortools package (64 bits) for Manylinux, Windows and MacOS.
You can also rebuild it from source https://developers.google.com/optimization/introduction/installing/source

Related

Trying to make sense of Python/Jupyter environment on MacOS

Background: while running Jupyter Notebook a new import was failing even though the library was installing successfully using pip3. Some of the set up for the code I was running was done in PyCharm which was using a virtual Python 3.8.2 environment. The failing import library is in the virtual environment so why isn't Jupyter seeing it?
I went looking and found that there are multiple versions of Python installed:
/Library/Python/2.7
/Library/Frameworks/Python.framework/Versions/3.8
/usr/local/bin/python3
/usr/local/bin/python3.8
/usr/local/bin/jupyter (included this in case it clarifies things)
/usr/bin/python
/usr/bin/python3
/usr/local/Cellar/python/3.7.6_1
/Users/xxx/anaconda3/bin/python3.7 (anaconda was uninstalled months ago so why is this still here?)
/Users/xxx/git/moat-ds/venv/lib/python3.8
I have installed pyenv and virtualenv and tried (unsuccessfully) to sort things out through this and similar articles. But all of this has only left me with questions:
what are these different directories doing?
when launched what is Jupyter notebook using for 'python 3' kernel?
where are the python packages stored when I run pip3 at the CLI (in pycharm packages are put in the \venv folder but otherwise?)
installing jupyter with pip from pyenv fixed my problem
brew uninstall jupyter
pip install jupyter
and after restarting your console it should be pyenv's jupyter
After trying #Akbar30bill's answer without success I did brew doctor and restarted my terminal and tried again and it worked. Wasn't linked correctly or something.

Do I have different python versions and which one I am working with?

I am confused about different python versions on my Computer and in Anaconda.
First: I use an iMac (OSX Catalina).I sometimes use the command line (Terminal on my iMac) directly and sometimes I use Anaconda Navigator (for example when I want to work with Jupyter Notebooks).
When I type python3 --version, I get the answer that I have python 3.8.0 installed. But recently, I installed the latest pip version with pip3 --user --upgrade pip. The answer I got was:
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
pip 20.0.2 from /Users/Andrea_5K/Library/Python/3.7/lib/python/site-packages/pip (python 3.7)
I wondered why in this message python 3.7 is referenced.
When I check my Library/Python folder in my user folder I see that I have a 3.7 folder and a 3.8 folder as well. Is there something wrong? Is pip 20.0.2 now installed on python 3.7 although I use python 3.8? And what does the WARNING message mean?

conda installed some package but still ModuleNotFoundError when import this package

I've found the solution:anaconda - graphviz - can't import after installation
I want to use graphviz and follow the commend in https://anaconda.org/anaconda/graphviz
run following in terminal
conda install -c anaconda graphviz
However no matter in Jupyter Notebook, python or Pycharm to import graphviz, it always shows
ModuleNotFoundError: No module named 'graphviz'
How to solve this problem? Thank you.
PS:
when run which python in terminal: it return /opt/anaconda3/bin/python, therefore I use anaconda environment by default. And I have only one environment in anaconda that is root.
when I run conda list in terminal, I can find this line :
graphviz 2.40.1 hefbbd9a_2
I found a weird thing:
my pip and conda use the same environment:
run :which pip
get : /opt/anaconda3/bin/pip
run : which conda
get : /opt/anaconda3/bin/conda
However when I run pip list, I cannot find graphviz and many other packages which shows in conda list. For these packages show in conda list but not in pip list, I also cannot import them no matter in Jupyter notebook, python, pycharm etc. Why this happens?
After using "conda install attrs", other package installations are working fine without any http connection or ModuleNotFoundError errors. Please try and let me know.

Why virtualenv shows all packages installed and do not install modules in virtualenv?

Question
I am not sure why when virtualenv active, pip freeze stills showing all modules when it suppose NOT to. What am I doing wrong?
On the terminal
I tried two ways to create a virtual env:
virtualenv my-virtualenv
virtualenv --no-site-packages my-virtualenv
then activate it
source my-virtualenv/bin/activate
Results
Both show all packages (when they suppose not to). Running command pip freeze I get:
(my-virtualenv)$ pip freeze
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
actionlib==1.11.9
angles==1.9.11
bondpy==1.7.19
camera-calibration==1.12.20
camera-calibration-parsers==1.11.12
catkin==0.7.6
cv-bridge==1.12.4
diagnostic-analysis==1.9.2
diagnostic-common-diagnostics==1.9.2
diagnostic-updater==1.9.2
dynamic-reconfigure==1.5.48
gazebo-plugins==2.5.13
gazebo-ros==2.5.13
...
rosnode==1.12.7
rosparam==1.12.7
rospy==1.12.7
rosservice==1.12.7
rostest==1.12.7
rostopic==1.12.7
rosunit==1.13.5
roswtf==1.12.7
tf2-ros==0.5.16
topic-tools==1.12.7
xacro==1.11.2
Running
(my-virtualenv)$ which python
/home/user/.../my-virtualenv/bin/python
(my-virtualenv)$ python -V
Python 2.7.12
and
(my-virtualenv)$ which python3
/usr/bin/python3
(my-virtualenv)$ python3 -V
Python 3.5.2
Hence, I even can use python3 when virtualenv is activated but it uses the pc installed module. Moreover, new installed packages are install in the pc and not the virtualenv and I can't install python3 in the vitualenv because it "exists" already (but in the pc).
I was having the same issue and it was because, somehow, Python configuration of ROS was generating it.
I solved it removing the source commands of ROS from the ~/.bashrc. E.g.:
source /opt/ros/melodic/setup.bash
source $HOME/ROS/aslam_ws/devel/setup.bash
By the way, I realised that, before changing anything, creating the environment from PyCharm works properly too (when in the terminal I still had the issue).
There must be a better solution but I haven't found it yet.

ERROR in install opencv in my python 3.6.6

I HAVE PYTHON 3.6.6 INSTALLED IN MY WINDOWS 7 PLATFORM BUT WHEN I TRIED TO INSTALL OPENCV PACKAGE IT SAYS REQUIREMENT ALREADY SATISFIED AND IF I TRY TO IMPORT CV2 IT SAYS NO MODULE .I'VE TRIED ALL POSSIBLE METHODS ON INTERNET WHAT SHOULD I DO
i tried to download opencv exe from sourceforge and copying cv2.pyd file and then pasting it in site packages
i tried pip install opencv_python-4.0.1-cp37-cp37m-win_amd64.whl
but nothing works
The error message says that you are asking PIP install a version of cv2 for 64-bit Python 2.7, and that installation is failing. So the installation is not happening because it's the wrong version. That might be because you don't have Python 2.7, or because you have a 32-bit processor, or both. Navigate to Python36\Scripts and issue the command pip install opencv_python. Then pip will find the appropriate file to download, and install it.

Resources