Source code of Python module that I installed from the web - python

How am I supposed to view the source code of a third party python module (pywhatkit) that I installed (using pip).
I also tried using the open() and read() functions, but it didn't work and the output shows.
Err: file not found

Python library source code often is stored in github.
In this case the source code you want you can find here:
https://github.com/Ankit404butfound/awesomepy/blob/master/program.py

If you are using an IDE like Pycharm, you can ctrl-click on that module name in your code and it will take you to the file with the definition. Normally, the installed modules are found in lib/site-packages/ of your python installation directory.

Related

How to fix this error on tabula.read_pdf() function in Python

I am trying to extract tables from a PDF file using Python (Pycharm).
I tried the following code:
from tabula import wrapper
object = wrapper.read_pdf("C:/Users/Ojasvi/Desktop/sample.pdf")
However, the error i got was:
"tabula.errors.JavaNotFoundError: `java` command is not found from this Python process. Please ensure Java is installed and PATH is set for `java`"
You probably need to add java to your system path. You can check those posts, they should help you in solving your problem:
How to Set Java Path On Windows?
Environment variables for java installation
I had every thing setup Java installed and Java path setup but was still getting same error, after spending half a day , I did below and everything worked.
I was using a python environment and running Tabula in python environment. I was getting error mentioned in questions.
I changed my python environment basically default one which is no environment and everything worked. I think Tabula is not able to detect Java once we are inside an python environment.

RobotFramework - Unable to import RemoteSwingLibrary

Screenshot of error in RobotFramework
Hello, I am trying to use the RemoteSwingLibrary in RobotFramework for testing. Other libraries I have been able to pip install just fine. However, RemoteSwing is not available with pip. I have a jar file of the library in the python27 folder with other libraries and have it explicitly listed in the path variable. Still receiving the error message that it does not see the module. Please advise. Thank you!
As the library is as jar file, Python interpreter with Python will not read it. You need to use Jython(java based python implementation)+Robot instead.
The reason for your issue is that you don't have it in the PYTHONPATH system/user variable.
This you can clearly see in the bug report where is listed.
You can add it to the system variables or use robot with a parameter where the path is specified:
robot --pythonpath c:\python37-32\libs\remoteswinglibrary-2.2.3.jar
btw. The guy from the different answer is absolutely missing the point. This is also part of the instruction for the installation RemoteSwingLibrary for pybot too and the reason for the existence of this project. The manual for installation is here.
You can look also here where is almost the same.

Using python "requests" module in a cygwin64 ZNC module

I'm positive that I'm doing something wrong, but I've looked around and the solutions presented have not worked for me.
I'm writing a bot for ZNC running under Windows 10/cygwin64 (which allows python based scripts). One of the functions I'm trying to write requires the "requests" python module, but when I try to run the python bot, it throws this error:
ImportError: No module named 'requests'
I've tried placing the "requests" source in the same folder as the bot's .py file. I've also tried easy_install to no avail.
Oddly enough, I was toying around with another python module that was required, and it worked as soon as I placed it's source in the same folder.
The version of python that ZNC is running is 3.4.
Edit: I noticed that cygwin64 stores the python bins and libs for ZNC under a specific sub-folder. I've therefore installed the "requests" module under the relative lib/site-packages directory. I think it worked, as far as the module being visible, but now ZNC crashes as soon as I load that bot script. It throws this:
cygwin_exception::open_stackdumpfile: Dumping stack trace to
znc.exe.stackdump
When I check that stackdump, it has the following:
Exception: STATUS_ACCESS_VIOLATION at rip=001801A62CD

Python - How do you import downloaded directories/modules?

This is the first time I have attempted to use anything other than what's provided by python.
I have recently gotten into pythons provided Tkinter, though due to some issues I decided to use another GUI, and heard that PyQt was highly recommended, so I downloaded that and looked into various tutorials. In these tutorials, I cannot seem to execute any of the import statements in said tutorials that relate to PyQt, primarily PyQt5 (I have checked I have the correct version number by the way).
So for instance:
import PyQt5
raises the error:
Traceback (most recent call last):
File "/Users/MEBO/PycharmProjects/Music/testing.py", line 1, in <module>
import Qt
ImportError: No module named 'Qt'
[Finished in 0.1s with exit code 1]
I have a lot of research into this. I've heard people talk of using pip to install modules, and I have done this be safe (as well as downloading it from the internet), I've tried changing the project interpreter to versions Python3/ 2.7/ 2.6, appending the path name to the sys.path directory, (which I really know nothing about to be honest, I was hoping I'd get lucky), though nothing seems to work.
Are you supposed to be able to just import a module off the bat, or do you have to set some things up first?
For windows download the package and extract it to (path where python installed)\Python27\Lib and then try to import.
Specific to PyQt
This package cannot just be downloaded and imported, it must be built because it is not pure python, it uses Qt (C++) and requires dependancies. Read this tutorial on installation.
There is also a very complete python package distribution, Anaconda, that includes pyqt and much more. Almost all the packages I ever looked at are in there.
In general to pure python code
In other cases, if you place modules/code that has been download into the directory that your python script is run from, you can import off the bat, or you can append/insert any folder to the sys.path.
# importer will search here last
sys.path.append('/path/to/code/')
# importer will search here second, right after script's directory
# this can be useful to override a module temporarily...
sys.path.insert(1,'/path/to/code/')

How do I find out what Python libraries are installed on my Mac?

I'm just starting out with Python, and have found out that I can import various libraries. How do I find out what libraries exist on my Mac that I can import? How do I find out what functions they include?
I seem to remember using some web server type thing to browse through local help files, but I may have imagined that!
From the Python REPL (the command-line interpreter / Read-Eval-Print-Loop), type help("modules") to see a list of all your available libs.
Then to see functions within a module, do help("posix"), for example. If you haven't imported the library yet, you have to put quotes around the library's name.
For the web server, you can run the pydoc module that is included in the python distribution as a script:
python /path/to/pydoc.py -p 1234
where 1234 is the port you want the server to run at. You can then visit http://localhost:1234/ and browse the documentation.
Every standard python distribution has these libraries, which cover most of what you will need in a project.
In case you need to find out if a library exists at runtime, you do it like this
try:
import ObscureModule
except ImportError:
print "you need to install ObscureModule"
sys.exit(1) # or something like that
You can install another library: yolk.
yolk is a python package manager and will show you everything you have added via pypi. But it will also show you site-packages added through whatever local package manager you run.
just run the Python interpeter and type the command
import "lib_name"
if it gives an error, you don't have the lib installed...else you are good to go
On Leopard, depending on the python package you're using and the version number, the modules can be found in /Library/Python:
/Library/Python/2.5/site-packages
or in /Library/Frameworks
/Library/Frameworks/Python.framework/Versions/Current/lib/python2.6/site-packages
(it could also be 3.0 or whatever version)...
I guess it is quite the same with Tiger
Considering that in every operating system most of python's packages are installed using 'pip' (see pip documentation) you can also use the command 'pip freeze' on a terminal to print a list of all the packages you have installed through it.
Other tools like 'homebrew' for macOS (used when for some reason you can't install a package using pip) have similar commands, in this specific case 'brew list'.

Categories

Resources