Openpyxl ImportError in Python 3.5.2 - python-3.x

I've tried everything recommended & still can't get openpyxl to work in Python 3. I've tried both the pip3 and "sudo apt-get install python3-openpyxl" installation methods & they seem to work fine, but when I open the python3 interpreter & type "import openpyxl", I still get the
ImportError: No module named 'openpyxl'.
It works fine in the python2 interpreter, but I just can't get get it installed for python3 & need to write my programs in python3.
I'm using Ubuntu 16.04 LTS Xenial Xerus & Python version 3.5.2. I've tried uninstalling & reinstalling the python3-openpyxl module but still get the error. Any help out there?
Thanks

I had the same problem on Mac and using:
pip3 install openpyxl
worked for me.
This works for Ubuntu 16.04 as well.

Since no one answered this, I will share my eventual work around. I backed up my files & installed Ubuntu 16.10 operating system from a bootable USB. Used Synaptic Package Manager to install openpyxl for Python3 & it is now working.
Not sure this is a bona fide solution, but it worked for my purposes.

Related

Run scrapyd in Python 3.6

I've been looking around and I can't seem to find an answer on how to run scrapyd in Python 3 and above. When I run it it keeps defaulting to python 2.7, though I recall reading in the docs or elsewhere that scrapyd supports python3:
https://scrapyd.readthedocs.io/en/stable/news.html#id1
Running on an AWS Ubuntu 18.04 server. What am I doing wrong? How can I change to Python 3.4 and above?
I'm having problems because I'm using abstract inheritance in my spiders which python 2.7 doesn't support.
Edit: I'm able to run Scrapyd in Python 3 using a virtual environment, but how would you do it without one?
Simplest solution is use a virtual enviroment.
Since you are using Ubuntu and you can make it work using a venv I assume you installed scrapy using pip instead of pip3. Since Py2.7 is the stardard reference to python in Ubuntu, when running pip it will execute pip for py2 instead of py3.
Another way would be uninstalling pip uninstall scrapy and installing it again using pip3 pip3 install scrapy. This should fix the reference to scrapy. If by any chance you also use scrapy in py2.7 and therefore can't uninstall, then you have another reason to use venv.

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.

import ortools in mac

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

Installation guide for ROS-Kinetic with Python 3.5 on Ubuntu 16.04

I'm having a ROS-node that uses Python 3.5 and I want to run it on ROS-Kinetic. This is supposed to run on Ubuntu 16.04 with Kernel 4.4.
I've read that it's complicated to match ROS-Kinetic with Python 3 because it's not officially supported...but I've also read that it is possible to do so...
There are several installation guides for specific packages and I've tried some of them but failed everytime.
What I've tried so far:
1) Installed ROS-Kinetic-desktop-full
2) pip3 install rospkg catkin_pkg
3) export PYTHONPATH = /usr/local/lib/python3.5/dist-packages
When I'm running catkin_make, the first error appearing says:
... ImportError: No module named genmsg ...
Can anyone please write an exact installation guide for making ROS-Kinetic run with Python 3.5 (without a virtual environment) or tell me what's missing in my installation?
Thanks in advance!
An alternative to Some progammer's answer, you could install the packages in global space
sudo apt-get install python3-yaml # you'll also need this
sudo pip3 install rospkg catkin_pkg
or add --user flag
pip3 install --user rospkg catkin_pkg
People used Python 3.5 + ROS-Kinetic in Ubuntu before (for example, check out cozmo_driver) and it should work according to REP3.
You are not exporting the right folder to PYTHONPATH. Try
export PYTHONPATH=/opt/ros/kinetic/lib/python2.7/dist-packages/

Trouble installing psycopg2 on a virtualenv using python3

The other day I asked a question about why I couldn't install psycopg2 on my mac. The problem, I realized, lies with python3.
I am working with flask and have been running in a virutalenv that uses python3. When attempting to install psycopg2 (using pip install psycopg2), it fails miserably. I attempted the same thing on the ubuntu virtual machine on my computer, with the same problem. However, when I attempt to install psycopg2 on a virtualenv using the python version installed on my computer (2.7.2), it works fine. It also works on the Ubuntu side.
Hence, the problem is with using python3 in the virtualenv. My friend and mentor helped me develop a workaround on my Ubuntu side. Essentially what we did was download python3, then modify the .bashrc to use the new python3 when typing python3 from terminal. Then, when we setup a new virtualenv using the downloaded python3, and attempted to download psycopg2, there wasn't the problem at all!
Now, so I want to use python3 with projects I am working on, and because I am deploying through Heroku, I need to use psycopg2 to link up my databases. Can anyone help me figure out a workaround on my mac side? Thanks!
P.S. -> Here's the link to my original question:
Can't install pscyopg2 on mac OS X 10.8.4
(Not sure what happened to the comments and original answer from the other stackoverflow user)
I solved this exact problem by installing python3-dev first.

Resources