Unable to import docx in python3 - python-2.7

I have installed both python2 and python3 in my windows machine. I wanted to use the python-docx, so I installed it using pip install . But I am unable to use it in python3. I get these results when i try to import in Python2:
]1
In Python3 :
]2

Python packages are installed in a particular Python installation. You have two Python installations and it looks like python-docx is installed in only one of them. What you need to work out is how to target the Python 3 installation for the python-docx install.
This question seems to address how to manage that.

Related

installing seaborn without sudo

I am trying to install seaborn without using sudo. I have already installed on my python 2.7 and windows 7 setting with the following cmd commands :
pip install pandas
pip install xlrd
pip install matplotlib
and they all were installed like charm.
`pip install seaborn` did not work
i have attached the error message.[last lines of emssage][1]
You may be interested in installing precompiled python wheel binaries for Windows.
That, or use something like Anaconda python.

how avoid Anaconda to hijack pip

I have 2 versions of Python installed on my PC (Windows 7, 64Bit).
Python 2.7 Version installed with Anaconda
Python 3.6 Version installed directly from python.org (the "regular IDLE")
Now, i would like to install the necessary packages on the 3.6 using pip, but anaconda keeps on hijacking the command.
For example, on typing in the cmd window:
pip install numpy
and i get:
Requirement already satisfied: numpy in
c:\users\georges\anaconda2\lib\site_packages
Which is the case for python2.7, but i was trying to install it for version 3.6 installed without Anaconda.
I tried re-installing pip hoping it would erase the hijacking by Anaconda2 ... failed.
I am contemplating to remove Anaconda2 altogether although i risk that in windows, removing a programme does not necessaraly remove the dependencies.
Any lead please ?
I think what you are looking for is pip3 install pip3 and you should be able install packages for python3
It should come as standard with python3 installation setup.
First check if it is there with
where pip3
For any further issues check this post
You don't need to uninstall anaconda2. Both python versions can co-exist and libraries different managed by different package installers pip for python 2 and pip3 for python 3 respectively.
Hope this answers your question.
Install it with pip3, because you want it for python 3:
pip3 install numpy

How to install difflib module in python 2.7 windows 10

Currently, I am facing difficulty installing difflib module in python 2.7 version in windows 10 system.
I want it to perform some text analytics analysis
tried using
apt-get install npm
npm install difflib
and
pip.exe install difflib
Solution for me was to save the difflib.py in the location where your .py file resides and then import it in your file.
install using pip should be a great idea, You can refer to the module related details here:
https://docs.python.org/2.7/library/difflib.html
If you face an issue installing it using pip, then the next way is to get the difflib.py from any working machine and keep it in the project directory itself, so that just importing the module itself will work.
This is the codebase reference from svn of python itself:
https://svn.python.org/projects/python/trunk/Lib/difflib.py

ImportError: 'No module named plotly.plotly' in LinuxMint17.3

Whenever I am trying to compile the following code to get a line graph shows some errors. But I don't know how to fix it. Here is my code :
import plotly.plotly as py
import plotly.graph_objs as go
# Create random data with numpy
import numpy as np
N = 500
random_x = np.linspace(0, 1, N)
random_y = np.random.randn(N)
# Create a trace
trace = go.Scatter(
x = random_x,
y = random_y
)
data = [trace]
py.iplot(data, filename='basic-line')
Shows the following error :
mks#mks-H81M-S /media/mks/KUTUBUDDIN1/test $ python datdaPlot.py
Traceback (most recent call last):
File "datdaPlot.py", line 1, in <module>
import plotly.plotly as py
ImportError: No module named plotly.plotly
mks#mks-H81M-S /media/mks/KUTUBUDDIN1/test $
How can this be fixed?
Added:
According to Spandan Brahmbhatt, I have installed pip by sudo pip install plotly. But still shows the following error:
You will need to install them first.
pip install plotly
pip install cufflinks
In my case I wanted to use in a Jupyter Notebook in Windows 10 but was getting the same error
ModuleNotFoundError Traceback (most recent call last)
in
----> 1 import plotly.express as px
ModuleNotFoundError: No module named 'plotly'
Considering you can also install Anaconda in Linux Mint and these came with Anaconda (in my case), if you decide to go with Anaconda you'll have at least two options to install plotly
Anaconda Prompt
Anaconda Navigator
Once installed, you'll be able to use it without any problem
1. Anaconda Prompt
Open Anaconda Prompt
Run the following command
conda install -c plotly plotly=4.8.1
2. Anaconda Navigator
Open Anaconda Navigator
Inside of it, go to Environment, select All in the dropdown and search for plotly.
Then select plotly from that list and click Apply.
I had the same problem. I accidentally was using a file in my working directory named ploylt.py. I removed that file form the directory and it works fine now.
First make sure that you have installed plotly
pip install plotly
(Test) Open an empty file, type
import plotly
and save it with a .py extension. Then run it. If this works, then your installation was ok. Move any other file named plotly (with any extension) in a different directory
It will hopefully work.
Based on ImportError: No module named plotly.plotly, I assume you have not installed plotly module.
You can install it using pip
$ pip install plotly
or
$ sudo pip install plotly
Use this:
conda install -c https://conda.anaconda.org/plotly plotly
Firstly, I'm new to plotly 2, and I am not sure I can make you understand since I'm a Chinese.
Anyway, you can try this, for me, it works:
import plotly
plotly.offline.init_notebook_mode(connected=True)
import plotly.offline as py
import plotly.plotly as py: this command will communicate with a Plotly Cloud or Plotly Enterprise. get_figure downloads a figure from plot.ly or Plotly Enterprise. You need to provide credentials to download figures: Getting Started with Plotly for Python
Refer:
Why Python line plot shows : Don't have an account? plot.ly
If you are using jupyter notebook in windows, then open the Anaconda Powershell Prompt(better to open in admin mode) and use the below command.
pip install plotly
pip install cufflinks
If you are using python from command prompt or which is set in the Environment variable then open the command prompt and use the same command mentioned above.
Both use different instance of python. So, if you use the above mentioned pip command in Anaconda PowerShell than it will install the libraries(plotly and cufflinks) in the python folder that comes with anaconda package but not in the python folder that you are using form the command prompt or which is set in the Environment variable.
I had the same problem. I found the solution by going through the directories.
pip install is installing in default python lib folder, all you have to do is copy the plotly folder from python lib to jupyter notebook lib folder. Since I am using windows the directories were as following :
c:\python34\lib\site-packages
c:\Anacoda3\Lib\site-packages
In case you searched around like I did until I found the link below, but looked here first, hopefully this will save you some frustration.
Delete the plotly.py file in your root folder. The one you created to test the get started code.
After you do that you'll be searching for a while again unless you delete the .pyc file (and get the ImportError: bad magic number in 'plotly': b'\x03\xf3\r\n').
https://github.com/plotly/plotly.py/issues/723
I was also having the same issue, but then it was due to different versions of python.
You might want to try the following command as well: (assuming you have python3 installed)
sudo pip3 install plotly
pip3 install plotly --upgrade
python3 <filename.py>
Please ensure that all the packages that are being used are installed for one python version only. As in my case all packages were installed for python3 but then I was trying to run my code with "python filename.py" and somehow that did not work.
Moreover, I also setup the credentials by following the link: https://plot.ly/settings/api. Register yourself using the link https://plot.ly/settings/api. Then create a file ~/.plotly/.credentials with your username and authentication key.
Hi I ran into something similar on my PC and here is what I advise you to do because it worked for me:
Open your Anaconda Prompt and run pip install plotly==4.1.1 cufflinks
Note that the 4.1.1 here is the version of plotly.
Installation:
Terminal:
- You can find more information about both plotly and cufflinks here.
Anaconda, Jupyter Notebook and Visual Studio Code:
- I believe I ran into this error because I did not install plotly on my PC so you can find more information on various ways of installing plotly here.
Like #Ananada, I had named my test file "plotly.py", i.e. the one containing the import plotly.graph_objects as go statement. So Python was trying to import the module from the script file I was running. Doh! Renamed it and problem solved.
To install plotly:
conda install -c plotly plotly
To check whether the installation was successful:
python3 -m pip show plotly
This shows the version of plotly installed in case of successful installation.
This worked for me!
Activate your environment again after installing the package if you are using a virtual environment.
Do source bin/activate if using bash. See https://docs.python.org/3/tutorial/venv.html.
Check your folder ... If this a temporary/test folder, maybe just like me you are wasting your whole day trying to understand why you cannot import .... .. ..
Maybe, just like happened to me - you have ANOTHER plotly.py file in your folder. Yes, that one.
Actually the module plotly is not pre-installed and we need it to be installed on our machines before using. It can be installed by using pip command :
pip install plotly
Also, we can install cufflinks. Cufflinks are smart plots.
pip install cufflinks
When you will get an error using anaconda navigator plotly install.
Go to the particular environment in Anaconda Navigator.
Then open terminal for the environment.
Install the packages.
On my Laptop, I had to use this code
!pip install pip plotly
Installing the "!" is key for my installation
All the best

Python3 pyserial library

I am working on small python scripts. Basically i am not a python programmer and very new to it. Recently i have been working on IOT protocol MQTT. I have installed a open source MQTT clinet based on python3 in my raspberypi board. And now i am facing a problem. I have python 2.7 and 3.2 installed.
My MQTT client work with Python3.x and i want to use pyserial library also which i am not able to , i am getting a error
Serial module not found
I goggled a bit and end up here.. Now it say that you need to install pip3 in order to install pyserial for python3.x.
I tried to install pip3 using this link , but end up installing pip2 using
pip install -U pip
I feel totally being messed up now. I just want to use pyserial while working with python3.x version.Can any one suggest me how?
Edit 1:
On Linux, Mac OS X and other POSIX systems, use the versioned Python commands in combination with the -m switch to run the appropriate copy of pip:
python2 -m pip install SomePackage # default Python 2
python2.7 -m pip install SomePackage # specifically Python 2.7
python3 -m pip install SomePackage # default Python 3
python3.4 -m pip install SomePackage # specifically Python 3.4
I recently came through this documentation given here . But it even give a error to me /usr/bin/python3 : NO module named pip. main : 'pip' is a package and cannot be installed directly.
Assuming you're using raspbian on your pi, you could install pip3 from the normal repositories:
apt-get install python3-pip
You can get the serial module the same way:
apt-get install python3-serial
I succeeded installing pyserial2.7 on a Mac running Yosemite and Python3.4
I entered the pyserial-x.y directory and run:
python3 setup.py install
I got lot of errors that I corrected one by one by editing the files containing the syntax errors. Only 2 types of errors are encountered:
- print needs ()
- except needs as instead of ,
So by correcting the dozen of errors with some patience, installation finish correctly.
I wonder why a syntactically correct version for Python3 is not ready!