Not able to import ggplot in python 3.5 - python-3.x

I have Ubuntu Gnome 16.04 both python 2.7 and python 3.5 installed.
I have installed ggplot in python 3.5 but not able to import it.
I am getting ImportError: No module named 'StringIO'.
Am I missing something? As far as I know StringIO module has been merged in io module in python 3.5.

Found the issue, some files have not been fully converted for python3.
Open file /usr/local/lib/python3.5/dist-packages/ggplot/ggplot.py and change
import StringIO
to this
from io import StringIO
I am not getting any error now but there could be some other files where python2 codes needs to be converted to work in python3.

Related

fbs freeze failed with Python 3.6.4

I have the following problem with fbs and Python: I tried to compile Python code and wanted to create an executable .exe file in windows. The command fbs run works fine, but fbs freeze fails.
Package versions:
Python 3.6.4
PyInstaller: 3.4
PyQt5: 5.9.2
Packages that I import:
import re
from itertools import chain
import os
import pandas
from PyQt5.QtWidgets import *
from fbs_runtime.application_context.PyQt5 import ApplicationContext
The output of fbs freeze --debug you see in the attached image:
I used the pyinstaller command to create the exe. This was possible without fbs. Just pyinstaller with the standard comments pyinstaller "...." --onefile --noconsole.
It worked with Python 3.6.4 and pyinstaller 3.4. Perhaps 3.5 would also work. But I know at least that Python 3.8.0 with the newest pyinstaller (even development version from git) doesn't work. I used PyQt5, but some older version 5.12....
It's a bit intransparent...
Best regards,
Markus
fbs runs perfectly fine with python 3.6.x (I am using 3.6.8, PyQt 5.9.2, PyInstaller 3.4).
The python compiler can sometimes get confused if another error happens earlier in the stack. Generally if fbs freeze errors when fbs run works, that points to a library-include error.
See my answer here to include necessary python library resources in your ./src/freeze/windows/ directory and try freezing again: The 'google-api-python-client' distribution was not found and is required by the application with pyinstaller

ImportError: cannot import name 'cluster_resolver'

I get this error when trying to setup Unity3d ml-agents
ImportError: cannot import name 'cluster_resolver'
Following https://github.com/Unity-Technologies/ml-agents/blob/master/docs/Installation.md tutorial
from tensorflow.contrib import cluster_resolver
Error happens when I try to run mlagents-learn --help
I am on MacOS with Python 3.6
Fixed by using Tensorflow 1.7.0 instead of 1.7.1 as in the tutorial.

Unable to use pypdf module

I have installed the pyPdf module successfully using the command pip install pydf but when I use the module using the import command I get the following error:
enC:\Anaconda3\lib\site-packages\pyPdf\__init__.py in <module>()
1 from pdf import PdfFileReader, PdfFileWriter
2 __all__ = ["pdf"]
ImportError: No module named 'pdf'
What should I do? I have installed the pdf module as well but still the error does not go away.
This is a problem of an old version of pypdf. The history of pypdf is a bit compliated, but the gist of it:
Use pypdf>=3.1.0. All lowercase, no number. Since December 2022, it's the best supported version.
Install pypdf
$ sudo -H pip install pypdf
You might need to replace pip by pip2 or pip3 if you use Python 2 or Python 3.
Use pypdf
import pypdf
WARNING: PyPDF3 and PyPDF4 are not maintained and PyPDF2 is deprecated - pypdf is the way to go!
Three potential alternatives which are maintained:
pymupdf: uses mupdf
pikepdf: Uses qpdf
pdfminer.six: A pure Python project. Don't confuse it with the unmaintained pdfminer
I've had the same error popping up after installing pypdf via pip and trying to import it in IPython (I'm using python 3.5.2):
In [5]: import pyPdf
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-5-a5780a4295f9> in <module>()
----> 1 import pyPdf
/home/mf/virtual_envs/pdfdataextract/lib/python3.5/site-packages/pyPdf/__init__.py in <module>()
----> 1 from pdf import PdfFileReader, PdfFileWriter
2 __all__ = ["pdf"]
ImportError: No module named 'pdf'
This was even after installing the pdf library using pip.
Luckily, there's a PyPDF2 library which works like a charm for me.
Use PyPDF2.
I've been using it in Python 3 (v3.5.2 to be precise), and it works quite well.
Here's a simple command that you can use to install PyPDF2.
sudo -H pip3 install PyPDF2
For using it:
from PyPDF2 import PdfFileReader
Let me know if you need any clarification.
Firstly, in your code you wrote:
from pdf import PdfFileReader, PdfFileWriter
Instead of:
from PyPDF2 import PdfFileReader, PdfFileWriter
Secondly use
pip3.x install pyPdf
instead of
pip install pyPdf if it will not work
I use pypdf2 , it work for me.
pip install pypdf2.
I use Ubuntu 16.04
I imported PDF library using python 3.8.5 as;
import PyPDF4
or
from PyPDF4 import PdfFileReader
it runs great.....
Your import code should read:
from pyPdf import PdfFileReader, PdfFileWriter

can't import http in python 3.5.1 but it works in cmd

I'm still learning python. I have windows 8 and had downloaded 2.7 as well as 3.5 because two modules I used in the past respectively used different python versions. Now though, I'm trying to run a script where the first line is import http.client or http. Neither of these work though. In cmd, python returns 3.5.1 currently and import http.client and import http return with no errors but in my IDE these don't work. Why not?
You can follow the Pycharm documentation here to change the Python version for your project from Python 2 to Python 3.
(In particular, Selecting Python interpreter for a project section)

Cannot import win32com.client module. Python Version 3.5.1 (32 bit)

I am having an issue importing the client module after installing the pywin32 extension for windows. I can import win32com with no issues at all, but I recieve an error when I try importing the client module. I realize this question has been asked numerous times, but here is what I have tried:
I have installed and reinstalled the correct version of pywin32. I have Python version 3.5 (32 bit) and I have installed the 3.5 32 bit file.
I have updated my PATH variable and my PYTHONPATH variable to include the locations of both the win32com and the client module.
I've manually ran the postinstall win32com script (not sure what this would do but I've read that it has helped some people)
It is worth noting that I can import sys, os, win32com, and win32com.client in the python IDLE, but when I run the import from a script in the same format, Python tells me it can't find the win32com.client module.
I receive the following error when running the win32com.client import from a script:
Traceback (most recent call last):
File "C:\Users\10023539\Desktop\pyscripts\outlook.py", line 3, in <module>
import win32com.client
ImportError: No module named 'win32com.client'; 'win32com' is not a package
I'm not sure what else to try at this point, any help would be greatly appreciated.

Resources