I am new to Python and tweepy. I have tried searching for an answer but haven't been able to get this working.
I have Java 6 (can't change to 7, for another project), python 2.7 and I have downloaded and extracted tweepy in my C drive.
Java and python are both in the PATH variables. I am trying to install tweepy and I keep getting this error.
C:\>cd C:\tweepy
C:\tweepy>python
Python 2.7.6 (default, Nov 10 2013, 19:24:24) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>setup.py build
File "<stdin>", line 1
setup.py build
^
SyntaxError: invalid syntax
>>> setup.py install
File "<stdin>", line 1
setup.py install
^
SyntaxError: invalid syntax
>>>
Where am I going wrong? Is it a configuration issue?
another way is to use pip (if you have it installed).
run
pip install tweepy
it should work just fine then.
download tweepy and unzip it in Desktop: https://github.com/tweepy/tweepy
2.rename it tweepy
open command prompt and type "cd desktop" then "cd tweepy"
type "python setup.py install"
You can also clone the git repo and do the following:
git clone git://github.com/tweepy/tweepy.git
cd tweepy
python setup.py install
Note: I assumed, you have added python to your PATH variable(if windows: https://www.pythoncentral.io/add-python-to-path-python-is-not-recognized-as-an-internal-or-external-command/)
I had the same problem. Despite the fact that I had already installed tweepy using pip install tweepycommand I was getting the "unable to import tweepy error".
I tried installing tweepy.asynchronous by running the following command and everything got fixed.
pip install tweepy[async]
Related
When I try to use
import praw
I get the following error:
ModuleNotFoundError: No module named 'praw'
I made sure to install praw beforehand in the command prompt, using pip install praw, so I'm not sure why it isn't working. I'm new to programming, so any insight would be greatly appreciated.
It depends on the python version (yours say Python3.9) in your environment.
Try pip3 to install your packages.
I would open up the terminal and do the following:
$ pip3 install praw
$ python3 myscript.py
I had the same problem and was looking into several ways to solve it.
For me the solution was as simple as changing the name of the pyhton file to some like "test" instead of "praw".
Yes, I named my file "praw.py" and was importing praw which was the origin of the error.
You could very well be having an issue with multiple python installations across your system. I suggest cleaning up your environment, and using a virtual environment.
You should run the following to build a clean virtual environment in your working directory:
python -m venv venv
This will create a virtual environment which should be free of system-wide packages, and is a nice and shiny clean python installation.
Now you'll want to activate it. You said you were on Windows, so then run
venv\Scripts\activate.bat if you're using CMD, or venv\Scripts\Activate.ps1 if you're using PowerShell.
Now try reinstalling praw with python -m pip install praw. You should now always be able to access praw if you're in this virtual environment.
If you're interested on reading the documentation on VirtualEnvs, here it is. You might also be interested in checking out the Hitchhiker's Guide to Python, especially the chapter on virtual environments and package management. (Do note that this last chapter uses pipenv instead of virtualenv.)
I've installed praw using pip3 install praw. So it is not showing in my system default python i.e python 2.7.17.
cam#cam:~$ python
Python 2.7.17 (default, Sep 30 2020, 13:38:04)
[GCC 7.5.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import praw
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named praw
>>>
[5]+ Stopped python
cam#cam:~$ python3
Python 3.6.9 (default, Oct 8 2020, 12:12:24)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import praw
If you want to use praw with python2 you'll have to use:
pip install praw
If you want to use praw with python3 you'll have to use:
pip3 install praw
Thank you all so much for your help, but I have finally figured out what was causing my problem! In a separate file for the bot called requirements.txt, I had:
git+https://github.com/Rapptz/Discord.py
PyNaCl==1.3.0
pandas
dnspython==1.16.0
async-timeout==3.0.1
I simply added praw==7.2.0, and it worked! I appreciate your efforts in trying to help me :)
I have installed python 2 and 3 and also have added the path to system variables. Everything except pip3 is working fine. Pip3 shows a error stating file is not found. Given below is the result I get on command line
Any direct pip3 command shows "The system cannot find the file specified". But if executed with "python3 -m" at the beginning then it runs fine. How can this be fixed so that pip3 can be accessed directly.
C:\Users>python3 -m pip --version
pip 20.1.1 from D:\Software\Python38\lib\site-packages\pip (python 3.8)
Python 2
C:\Users>python2
Python 2.7.18 <v2.7.18:8d21aa21f2, Apr 20 2020, 13:25:05> (MSC v.1500 64 bit <AMD64>] on win32
Type “help”, “copyright”, “credits” or “license” for more information.
>>> quit<>
C:\Users>pip2 —-version
pip 20.2.3 from d:\software\python27\lib\site-packages\pip (python 2.7)
Python 3
C:\Users>python3
Python 3.8.5 <tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) [MSC v.1926 32 bit <Intel>] on win32
Type “help”, “copyright”, “credits” or “license” for more information.
>>> quit<>
C:\Users>pip3 —-version
Fatal error in launcher: Unable to create process using "d:\software\python38\python.exe" "D:\Software\Python38\Scripts\pip3.exe" —-version’: The system cannot find the file specified.
I'm trying to use pdftotext, but it won't import.
I'm running Windows 10 (64 bit) on a Lenovo IdeaPad S340, a work laptop.
Following the directions here and here (which were super helpful), I:
Installed Microsoft Visual C++ Build Tools.
Installed Anaconda.
Got the latest version of Anaconda and updated it, using a separate Anaconda3 commands for each of these steps. I don't recall the commands, and haven't found them again.
Updated Microsoft Visual 14.
Used conda to install poppler via Anaconda3 command: conda install -c conda-forge poppler
Used pip to install pdftotext via Anaconda3 command: pip install pdftotext
After that:
This happens in the Python 3.8 (32 bit) command prompt:
>>> import pdftotext
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pdftotext'
>>>
This happens in IDLE's Python 3.75 Shell (64 bit):
>>> import pdftotext
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import pdftotext
ModuleNotFoundError: No module named 'pdftotext'
>>>
This happens in the Anaconda3 command prompt:
import pdftotext
'import' is not recognized as an internal or external command,
operable program or batch file.
This also happens in Anaconda3 command prompt:
pip install pdftotext
Requirement already satisfied: pdftotext in c:\programdata\anaconda3\lib\site-packages (2.1.4)
Does that mean it only runs in Python 2? How would I have checked that beforehand? If it does only run on Python 2, can you recommend a Python 3 package/module/library (what is the difference, btw?) for reading a PDF into a plain text file?
Thanks for your help!
Update:
I started over with a new user on the same machine and OS (the other user had a space in the name, so its filepath had a space, which can cause problems). I'm hitting the same problem.
I have Python 3.7.6 and 3.8.1. Python 3.7.6 is what shows up when checking the version through the Anaconda3 prompt python -V (3.7.6.final.0 when using conda info).
I also have:
Anaconda Version "custom", Build py37_1.
conda 4.8.2, py37_0, Channel conda-forge.
poppler 0.84.0, h1affe6b_0, conda-forge.
pdftotext 2.1.4, pypi_0, pypi.
I found Python here: C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64.
I searched with my eyes all over the program files, user files, and on the Anaconda Navigator, and I ran a search of my entire C drive for 'pdftotext', and I didn't find anything about pdftotext.
Attempting from IDLE's Python 3.7.6 shell didn't work either.
Update:
I figured it out, sorta. pdftotext is not working as a Python import, as the example code in PyPI uses it. But, it does work as a command line tool that is part of Xpdf, with no additional installation after the steps.
I used the command in the Anaconda3 PowerShell command prompt:
pdftotext C:\filepath\file.pdf
It then created a text file with the same name and saved it in the same folder. There are additional options for the command outlined on the Xpdf page I linked above (like setting your file name).
Buuuut, this is not a satisfying solution. I'm able to take care of my current use-case task, with an additional step, but I'm still not able to call pdftotext from within a Python program.
Update:
If you install pdftotext using Anaconda and conda, then importing it seems to only work when you run it in the Python interpreter from within the Anaconda3 shell.
So, I had to switch to the Python interpreter mode in the Anaconda3 PowerShell first: python
Then, I could import pdftotext with no error: import pdftotext
It looked like this:
(user)> python
Python 3.7.6 (default, Jan 8 2020, 20:23:39) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pdftotext
>>>
pdftotext is not a module but a command.
So you can do the following
import os
file_path = "C:\documents\mypdf.pdf"
# writing data in variable
text = os.popen("pdftotext {}".format(file_path)).read()
# writing data in file
os.system("pdftotext {} {}".format(file_path, "data.txt"))
Okay, I figured it out! If you install pdftotext using Anaconda and conda, then importing it seems to only work when you run it in the Python interpreter from within the Anaconda3 shell.
So, I had to switch to the Python interpreter mode in the Anaconda3 PowerShell first:
python
Then, I could import pdftotext with no error:
import pdftotext
It looked like this:
(user)> python
Python 3.7.6 (default, Jan 8 2020, 20:23:39) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pdftotext
>>>
Ooor, a second partial solution is that it works as a command line tool that is part of Xpdf.
I needed no additional installation after the steps taken in the problem post. I used the command in the Anaconda3 PowerShell command prompt:
pdftotext C:\filepath\file.pdf
It then created a text file with the same name and saved it in the same folder. There are additional options for the command outlined on the Xpdf page I linked above (like setting your file name).
The problem with the second solution of using it from the command line is that if you want to do something with the text file afterwards, you have to run another command or script. All it does is read it to a file.
I had the same problem but after performing the following, it worked like charm!
sudo apt install build-essential libpoppler-cpp-dev pkg-config python3-dev
pip install pdftotext
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',
)
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.