Trying to import docx in Python - ms-word

Fair Warning: I am extremely new to python, so please excuse any dumb mistakes I make =)
I would like to be able to open/close/manipulate/read Word documents (docx files) on my Mac using Python. The python-docx module looked really useful, so I have been trying to install it on my system, to no avail.
Here's what I've done so far:
Checked that I do indeed have python installed using the python --version command in terminal. I have version 3.7.0, so all good there.
Checked that I do indeed have pip installed - I was able to use pip install and pip uninstall commands, so all good. I also upgraded my pip version using pip install --upgrade pip to pip-19.1.1
Following the online documentation (see here), I tried pip install python-docx. This seemed to work just fine, and after the progress bar loaded all the way I saw:
Successfully built python-docx
twisted 18.7.0 requires PyHamcrest>=1.9.0, which is not installed.
Installing collected packages: python-docx
Successfully installed python-docx-0.8.10
I wasn't completely sure what pyhamcrest was, but I installed it anyway just to be safe using pip install pyhamcrest
As other sites suggested, I also tried to install Pillow, lxml, and python-dateutil using their respective install commands, and in each case saw the Requirement already satisfied: message, with an anaconda path listed.
Frustrated, I also tried easy_install python-docx, the manual version, and even pip install docx . In all cases, when I run IDLE and type from docx import Document or just import docx, I get the following message in the shell:
`Traceback (most recent call last):`
`File "/Users/[my_name]/Desktop/Medical.py", line 3, in <module> `
`import docx`
`ModuleNotFoundError: No module named 'docx'`
Could anyone help point me in the right direction? Thank you very much.

The Anaconda Python distribution has its own system of installation of packages.
After the installation of Anaconda, the variable $PATH has been modified so that anaconda python was the first, and OsX's python in the last position.
If you type "python" in a shell will execute the anaconda python, instead of the standard OsX python (which is 2.7, not 3.x).
Following the instructions of the package python-docx, you have installed it using pip, which is the default method for installing packages, but this method is not valid for Anaconda Python. So, you finished installing python-docx for the python 2.7 of OsX.
To install packages for anaconda, you must run the command
conda install <package>
The python-docx module for anaconda can be found in a separated repository called conda-forge; typing the command
conda install -c conda-forge python-docx
you will install the package and the requested dependencies.
Other useful commands are:
anaconda-navigator for exploring the Anaconda system
anaconda-project for managing projects with anaconda
idle3 for Anaconda Python shell.
Before start coding, run anaconda-navigator and take a look at the 'Learning' section.
For a better experience, I suggest PyCharm IDE for Anaconda from JetBrains.

Related

Plotly installed, but VSCode doesn't seem to think so

I'm trying to learn how to use Plotly using VSCode, but the minute I run my code from the terminal, it says ModuleNotFoundError: No module named 'plotly' Any idea why this is happening? Python is installed via Anaconda, and if I try to do pip install plotly it tells me it's already installed. I've tried nearly everything I can find about this issue and nothing works. Any suggestions would be appreciated.
I'll also add that when I do pip install plotly it gives the following:
Requirement already satisfied: plotly in /Users/username/opt/anaconda3/lib/python3.8/site-packages (4.14.3) Requirement already satisfied: retrying>=1.3.3 in /Users/username/opt/anaconda3/lib/python3.8/site-packages (from plotly) (1.3.3) Requirement already satisfied: six in /Users/username/opt/anaconda3/lib/python3.8/site-packages (from plotly) (1.15.0)
It's possible that you have multiple python versions installed and pip installed plotly for the wrong version. Try to do pip --version and in your code (before the plotly import) do
import sys
print(sys.version)
to see if the python versions match. If they don't, you may have to call pip3 install instead.
(Would have posted this as a comment, but don't have enough reputation).
Accidental fix found: I was working with the bash shell on the VS Code terminal. I switched to the zsh shell by doing exec zsh. When I ran the file using the zsh shell, everything worked.

Install conda package from Google Datalab

I'm looking to use the ospc taxcalc package in a Google Datalab notebook. This package must be installed via conda.
Datalab doesn't have conda by default, so this method (from https://stackoverflow.com/a/33176085/1840471) fails:
%%bash
conda install -c ospc taxcalc
Installing via pip also doesn't work:
%%bash
pip install conda
conda install -c ospc taxcalc
ERROR: The install method you used for conda--probably either pip install conda or easy_install conda--is not compatible with using conda as an application. If your intention is to install conda as a standalone application, currently supported install methods include the Anaconda installer and the miniconda installer. You can download the miniconda installer from https://conda.io/miniconda.html.
Following that URL, I tried this:
%%bash
wget https://repo.continuum.io/miniconda/Miniconda2-latest-Linux-x86_64.sh
bash Miniconda2-latest-Linux-x86_64.sh
wget works, but the bash command to install just kept in "Running..." state for seeming perpetuity.
This seems to be due to the conda installer prompting for several Enter keystrokes to review the license, and then for a yes indicating acceptance of the license terms. So conda's silent mode installation looked promising:
%%bash
bash Miniconda2-latest-Linux-x86_64.sh -u -b -p $HOME/miniconda
This produced the following warning:
WARNING: You currently have a PYTHONPATH environment variable set. This may cause unexpected behavior when running the Python interpreter in Miniconda2. For best results, please verify that your PYTHONPATH only points to directories of packages that are compatible with the Python interpreter in Miniconda2: /content/miniconda
And doesn't make available the conda command:
%%bash
conda install -c ospc taxcalc
bash: line 1: conda: command not found
There is a pending github issue tracking this work - https://github.com/googledatalab/datalab/issues/1376
I believe we will need to install conda and use that for python, pip and all other python packages, and in the interim it may not be possible to mix the two python environments. However someone with more experience with conda might know otherwise.
As of the 2018-02-21 release, Datalab supports Conda and kernels are each in their own Conda environment.

Struggling with installing Celery for Tornado

So, I am trying to test Celery with Tornado, but having difficulty with Celery installation.
I am using Ubuntu 12.04 LTS. I have ad Tornado working for months now. Then tried to install Celery using python -m pip install tornado-celery. But my import commands in test script don't work.
For example, I get an ImportError: unable to locate tasks when I do import tcelery, tasks.
So, I tried to uninstall Celery thinking something went wrong. Tried apt-get remove tornado-celery. I get an error saying Unable to locate package tornado-celery. So, I re-install and then it says Requirement already satisfied.
What is going on?
tasks isn't a module that comes with celery - the idea of that example is that you'd write your own file tasks.py to put your tasks in. There's an example of this in https://github.com/mher/tornado-celery/tree/master/examples
Your installation is fine (as far as I can tell), but if you do want to uninstall it, use the same program to uninstall as you did to install: something installed with pip install can only be uninstalled with pip uninstall, not apt-get uninstall.

Unreadable Notebook - Unsupported nbformat version 4 on windows

I finally was able to install ipython on my Windows 7 PC and it runs without any errors. The problem is that I used to code in ipython but in MAC. Now that I am trying to upload my previous notebooks I receive the following error:
Unreadable Notebook: MyFile.ipynb Unsupported nbformat version 4
I found this answer for my question but unfortunately that is not for windows and did not resolve my problem. It is worth to mention:
ipython --version
produces:
2.3.1
Any help or comment on this is much appreciated.
Thanks
It took me a while to figure this out but I got the first lead from user "cel". I used to have multiple versions of python (2.7 and 3.4). I removed python 3.4 because it's not compatible with spark yet. Next, I had to remove WinPython3.4 and replace it with WinPython2.7 so it can integrate with python 2.7 installed on my PC. Finally, I installed python 2.7.9 and set the C:/Python27/Script as a part of system environment variable. After doing all this I ran the following commands:
pip uninstall ipython
This helped me to remove older version of ipython. Then:
pip install ipython
This installed the latest version of ipython on my windows pc. Finally:
pip install notebook --upgrade
To upgrade notebook to latest version. Right now, ipython os installed and and should work fine doing this:
ipython notebook
Had no problem importing my previous .ipynb after all of the above.
Good luck to you all.
I have the same problem on Linux. Simply doing:
sudo pip install notebook --upgrade
worked for me. I have python 3.4 and 2.7 and unlike the answer by nimafl, there was no need for me to remove one them or to first uninstall ipython. A simple upgrade did the trick. Now instead of version 2.3.1 I have version 4.0.3 of ipython.

PyEphem running error on Ubuntu

I have read previous posts on installation issues. Nothing seems to work.
I have Ubuntu 14.04LTS, 32 bit, Anaconda python ver 2.7.
I installed pyephem using sudo pip install pyephem [after checking I have python-dev, and latest pip] Installation said it was successful.
When I run Python 2.7 and try to import ephem, it says Import error:
No Module named _libastro.
Any help will be appreciated.
If you are using Anaconda and have activated your conda environment, you should not need to use sudo — that might aim the install at your system Python, the one governed by the root account and by sudo, instead. You could try activating your conda environment and then just doing conda install ephem because it comes built in to conda, you do not need pip plus a compiler to try installing it!