No module named main, wkhtmltopdf issue - python

I'm new in python, but all search results i found was useless for me.
C:\Users\Aero>pip install wkhtmltopdf
Collecting wkhtmltopdf
Using cached wkhtmltopdf-0.2.tar.gz
Installing collected packages: wkhtmltopdf
Running setup.py install for wkhtmltopdf
Successfully installed wkhtmltopdf-0.2
C:\Users\Aero>python
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:43:06) [MSC v.1600 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import wkhtmltopdf
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python34\lib\site-packages\wkhtmltopdf\__init__.py", line 1, in <module>
from main import WKhtmlToPdf, wkhtmltopdf
ImportError: No module named 'main'
That is happening all the time. Thanks for any help.
Update:
I find that installing Python 2.* makes it okay, cause of main module isn't correct while using print (Using 2.* version).
But i still want to know, it there any ways?

i solve it installing it this way, i hope it work for you
pip install django-wkhtmltopdf

It wasn't working for me for the first time, but after a PyCharm restart I could see anything. This might work for you: (Tested on Python 3.3.0)
import wkhtmltopdf
from wkhtmltopdf.main import WKhtmlToPdf
var = WKhtmlToPdf(
url='http://www.example.com',
output_file='~/example.pdf',
)
var.render()

If none of the other options work, it might be something wrong with your cache. Try uninstalling wkhtmltopdf and django-wkhtmltopdf and reinstalling without the cache:
pip uninstall django-wkhtmltopdf wkhtmltopdf
pip install --no-cache-dir wkhtmltopdf==0.2
pip install --no-cache-dir django-wkhtmltopdf==3.2.0
(Note that the above wkhtmltopdf and django-wkhtmltopdf version numbers may be different in your case.)

Seems there is some error with package installation of wkhtmltopdf. It wasn't working for me then i uninstalled the package and re-installed it by doing
python -m pip uninstall wkhtmltopdf
and then
python -m pip install wkhtmltopdf
it worked for me.try this it may work.

Related

Can't import module installed with pip (anaconda python)

I'm trying to use the ReadIM package with an anaconda environment (anaconda 4.7.12, python 3.8, pip 19.3.1), thus requiring me to use pip install readIM which succeeds, with the package found in conda list and pip list.
I have read a lot of posts talking about using the correct python and pip paths, my python where shows only my anaconda path, where I ran conda install pip beforehand, and then pip -V shows my pip is in my conda path.
I have tried conda update --all and pip uninstall readIM. I also read that it could be an issue with Jupyter notebook, hence in the conda command prompt I tried python then import readIM, which still gave me the same import error.
As advised on the source page, I tried installing by running python setup.py build install/python setup.py install in the source directory, however this gave me an error
cygwin TypeError: '>=' not supported between instances of 'NoneType' and 'str'
I am at a loss, any ideas?
Thanks,
Mustafa.
UPDATE:
Managed to compile it from source successfully, but still get the same error:
(base) C:>python -m pip install ReadIM-0.8.2.tar.gz
Processing c:\readim-0.8.2.tar.gz
Building wheels for collected packages: ReadIM
Building wheel for ReadIM (setup.py) ... done
Created wheel for ReadIM: filename=ReadIM-0.8.2-cp37-cp37m-win_amd64.whl size=219546 sha256=90f8960a6f1f80ae62dc18eab4bcd31fb2a6dfd7da364a5c15fc37e6e2ce0360
Stored in directory: C:\Users\mi4517\AppData\Local\pip\Cache\wheels\d6\a9\11\936e986255027bb654601b322a3431f9bcc3fde72ebb406835
Successfully built ReadIM
Installing collected packages: ReadIM
Successfully installed ReadIM-0.8.2
(base) C:>python
Python 3.7.5 (default, Oct 31 2019, 15:18:51) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
import readIM
Traceback (most recent call last):
File "", line 1, in
ModuleNotFoundError: No module named 'readIM'>
Following their instructions (python setup.py build install then python setup.py test) yields a successful build but a failed test:
C:\ReadIM-0.8.2>python setup.py test
Traceback (most recent call last):
File "setup.py", line 41, in
assert os.path.isdir(testFileDir)
AssertionError
SOLUTION
It was installing correctly, just that I was importing it incorrectly in Python. I was doing import readIM or import readim when it should be import ReadIM I did not know it was case sensitive!
Thank you for your help, apologies for the trivial mistake on my part.
I had faced a similar issue. With your conda environment activated, type
which pip
Check if it shows the path to pip in your environment. In my case, it was not. It was showing path to some other pip. So pip install was installing in that environment. To fix use the full path of pip, like below
~/anaconda3/envs/my_env/bin/pip install ...
To avoid this issue follow these steps
open Anaconda prompt
type this command conda install -c conda-forge imread
after installation open jupiter notebook.
type import imread then run.
It was installing correctly, just that I was importing it incorrectly in Python. I was doing import readIM or import readim when it should be import ReadIM I did not know it was case sensitive!
Thank you for your help, apologies for the trivial mistake on my part.

Although I install python-telegram-bot, error of no module named 'telegram'

I installed telegram packages. But when I try to run the simple example, echobot.py, I got an error:
Traceback (most recent call last):
File "echobot.py", line 8, in <module>
import telegram ImportError: No module named 'telegram'
Can anyone help me?
I install using git:
$ git clone https://github.com/python-telegram-bot/python-telegram-bot
after this:
$ python -i
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:01:18) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
import telegram
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'telegram'
You are not installing it. You are just downloading it.
Run these:
cd python-telegram-bot
python setup.py install
(stated in readme of the GitHub page)
Alternatively, you can use pip. It's easier to use.
pip install python-telegram-bot
For my case, I solved it this way.
pip install telegram
I noticed when I import telegram.ext, it does not find .ext. The issue was caused by telegram and python-telegram modules being installed. Delete these and install only python-telegram-bot. It should work.
Thre problem is in line with smth like
sys.path.append(os.path.join(os.path.abspath('.'), 'lib'))
in bot_gae.py.
You have to point at REAL place, where you've installed python-telegram-bot.
In my case it's ./lib in project directory.
If you have named your python file as telegram.py then it will throw this error because the program is calling ext function from the file itself.
Try renaming your python file to something else it will work.
In my case, I had two python versions installed.
A quick solution is to idetify which python your code is using. Then go to bin directory where the python is installed. Find the pip binary name inside that using command
ls -lrt | grep pip
In my cases the name was pip3.6. So use then use that pip name and execute from same directory
pip3.6 install python-telegram-bot
Long term fix is to add your pip3.6 shortcut in /usr/bin or /usr/loca/bin and install packages using pip3.6 command
Try to uninstall it by pip uninstall python-telegram-bot
And after that install it again pip install python-telegram-bot
Install
pip install django-telegrambot
Configure your installation
settings.py
INSTALLED_APPS = (
...
'django_telegrambot',
)

Install tkinter in python3.6 on Ubuntu

+--------+-----------------------------------+
| OS | Ubuntu 12.04 |
+--------+-----------------------------------+
| Python | 2.7, 3.2 and source installed 3.6 |
+--------+-----------------------------------+
Since there are 2 versions of Python 3, anything installed from the repository doesn't work for Python 3.6. The latest version of Python in the repositories is 3.2, so I need source installs or through pip3.6.
After starting python3.6 I tried to import tkinter, which gave the following error. Even though help('modules') returned a list of modules which included tkinter.
import tkinter
ModuleNotFoundError: No module named '_tkinter'
I tried doing the same in python3.2 and there were no errors. tkinter._tkinter gave the location of tkinter library for python3.2
I cd'd into the python3.6 directory which has all library files and indeed it was missing the tkinter.so object file.
How do I fix the error?
I would like to get tkinter/tkagg working as it seems all the modules/ package are already installed.
After googling some more, I found I need to build python3.6 again, but this time with Tcl/Tk options while running configure. I'd rather not. It takes 1hr approx to install python3.6 from scratch.
Is there some other way where I can tell python3.6 where Tcl/Tk is located?
The problem isn't telling python where tcl/tk is. After messing around with python3.6's source code, and then comparing python3.6 with python3.2, I found out that tkinter calls _tkinter which isn't a python file, it's an .so(shared object) file that python builds during installation via setup.py that uses gcc, that somehow may involve distutils.
The new and more appropriate question is how do I build,
_tkinter.cpython-36m-i386-linux-gnu.so from tcl/tk?
Note : I do have tcl/tk installed, which I have confirmed using tclsh and wish.
run from terminal:
sudo apt-get install python3.6-tk
or just reinstall completly:
sudo apt-get install python3.6
Python version 3.6.4 (Ubuntu 18.04 LTS)
sudo add-apt-repository main
sudo apt-get install python3-tk
I faced a similar problem to yours, I am giving the details of it and how I solved it.
On Ubuntu 16.04 LTS, I have Python 3.5.2 and Python 2.7.12 but I would like to experiment Python3.6 (for various reasons like this one, for example). So I relied on this post:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python3.6
When I tried to run a module using tkinter, I got this error message:
Traceback (most recent call last):
File "/usr/lib/python3.6/tkinter/__init__.py", line 37, in <module>
import _tkinter
ModuleNotFoundError: No module named '_tkinter'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "bill.py", line 3, in <module>
from tkinter import Canvas, Label, Tk, StringVar, Button, LEFT
File "/usr/lib/python3.6/tkinter/__init__.py", line 39, in <module>
raise ImportError(str(msg) + ', please install the python3-tk package')
ImportError: No module named '_tkinter', please install the python3-tk package
I tried to install tkinter as the message above asks:
sudo apt-get install python3-tk
[sudo] password for begueradj:
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3-tk is already the newest version (3.5.1-1).
0 upgraded, 0 newly installed, 0 to remove and 8 not upgraded.
Obviously, I still can not use tkinter for Python 3.6. How to fix this problem?
My first blind attempt did not work:
sudo apt-get install python36-tk
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package python36-tk
The second one works:
sudo apt-get install python3.6-tk
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
tix python3.6-tk-dbg
The following NEW packages will be installed:
python3.6-tk
0 upgraded, 1 newly installed, 0 to remove and 8 not upgraded.
Need to get 74.6 kB of archives.
After this operation, 165 kB of additional disk space will be used.
Get:1 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu xenial/main amd64 python3.6-tk amd64 3.6.5-1+xenial1 [74.6 kB]
Fetched 74.6 kB in 0s (301 kB/s)
Selecting previously unselected package python3.6-tk:amd64.
(Reading database ... 324106 files and directories currently installed.)
Preparing to unpack .../python3.6-tk_3.6.5-1+xenial1_amd64.deb ...
Unpacking python3.6-tk:amd64 (3.6.5-1+xenial1) ...
Setting up python3.6-tk:amd64 (3.6.5-1+xenial1) ...
And that solved my problem:
~/python3.6
Python 3.6.5 (default, Mar 29 2018, 03:28:50)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
>>>
Python version 3.6.4 (Ubuntu 18.04 LTS)
I was having the same error: tkinter module not found. Even after trying to install via pip
$ pip install tkinter
I got this error, below
Collecting tkinter
Could not find a version that satisfies the requirement tkinter (from versions: )
No matching distribution found for tkinter
I did this tried to install tkinter for Python3.6 by running the command. It worked for me.
$ sudo apt-get install python3.6-tk
Installed python3.8.2 on ubuntu 20.04, tried importing tkinter but failed. Got this error:
da0xxx:~/python_trn/pygui$ python3 -m tkinter
/usr/bin/python3: No module named tkinter
but ran:
da0xxx:~/python_trn/pygui$ sudo apt-get install python3-tk
now able to import tkinter!
da0xxx:~/python_trn/pygui$ python3
Python 3.8.2 (default, Apr 27 2020, 15:53:34)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
import tkinter as tk
Thanks above!
Try these lines, It might help
os.environ['TCL_LIBRARY'] = r'C:\Users\asus\AppData\Local\Programs\Python\Python36-32\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Users\asus\AppData\Local\Programs\Python\Python36-32\tcl\tk8.6'
Recheck path before executing.

psycopg2 module cannot be found by Python2.7

I installed psycopg2 via pip, but my programs are having trouble finding it.
So, I tried to install psycopg2 via pip again:
user#ubuntu:~/Desktop/progFolder$ sudo pip install psycopg2
Requirement already satisfied (use --upgrade to upgrade): psycopg2 in /usr/local/lib/python2.7/dist-packages
Cleaning up...
Then I tried to use a program that imports it:
user#ubuntu:~/Desktop/progFolder$ python myProg.py
Traceback (most recent call last):
File "myProg.py", line 6, in <module>
import psycopg2
ImportError: No module named psycopg2
And I have tried just importing directly in python:
user#ubuntu:~/Desktop/progFolder$ python
Python 2.7.5 (default, Nov 9 2014, 14:14:12)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named psycopg2
So I printed my python path.
>>> import sys
>>> print sys.path
['', '/usr/local/lib/python27.zip', '/usr/local/lib/python2.7', '/usr/local/lib/python2.7/plat-linux2', '/usr/local/lib/python2.7/lib-tk', '/usr/local/lib/python2.7/lib-old', '/usr/local/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/site-packages']
And noticed that the path does contain the path to psycopg2.
psycopg2 in /usr/local/lib/python2.7/dist-packages
So, I have no idea on why this is happening. Any help would be appreciated.
UPDATE:
I have done
>>>help()
>>>modules
And psycopg2 was not listed among the other modules. (this does not help me but may help you help me)
Your pip looks ok (that is, it's the system/default one). Your Python executable, however, is something that didn't come by default with 14.04 LTS (e.g., on my 14.04 system, it's /usr/bin/python). Did you install that Python yourself? Then you need to install (and use) the corresponding pip as well. (Normally, Python would have come with a pip installation, but apparently in this case, it didn't.)
pip can be fairly simple installed from its installation instructions.
Though first, verify that
you did install /usr/local/bin/python yourself. That is, it didn't come with some other piece of software that you installed and that, along the way, decided to install Python there.
you want to use /usr/local/bin/python (I guess it is a more recent version of Python 2.7; the default 14.04 LTS one appears to be 2.6.7 as of 2015-08-03).
From your python path print, it looks like it doesn't have /usr/local/lib/python2.7/dist-packages included in it. You can add it in one way by:
sys.path.insert(0, "/usr/local/lib/python2.7/dist-packages")

Can't install module with python-pip properly

I would like to install a module but pip is not installing it in the right directory which I assume should be /usr/local/lib/python2.7/site-packages/. After all, I just installed Python 2.7.2 today. Originally I had 2.6.5 and had installed modules successfully there. So I think something is wrong with my Python path.
How to have all my module installations go to the proper python2.7 directory?
s3z#s3z-laptop:~$ pip install requests
Requirement already satisfied: requests in /usr/local/lib/python2.6/dist-packages/requests-0.6.1-py2.6.egg
Installing collected packages: requests
Successfully installed requests
s3z#s3z-laptop:~$ python
Python 2.7.2 (default, Oct 1 2011, 14:26:08)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named requests
>>> ^Z
[3]+ Stopped python
Also here is what my Python directories look like now http://pastie.org/2623543
After you installed Python 2.7, did you install the Python 2.7 version of easy_install and PIP? The existing installations are configured to use Python 2.6 by default which may be causing your issue.
You are probably using pip linked to python2.6, instead of 2.7. If you have installed pip properly with python2.7, you can do:
pip-2.7 install requests
If not, try installing this way:
curl -O http://python-distribute.org/distribute_setup.py
[sudo] python2.7 distribute_setup.py
curl -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py
[sudo] python2.7 get-pip.py

Categories

Resources