Pyperclip error in Pythonista on iPad Pro - python-3.x

I am learning Python 3 using a Udemy course. One of the course modules asks us to install Pyperclip in order to try out simple code is the console.
import pyperclip
pyperclip.copy(‘Test’)
pyperclip.paste()
I believe this should output the word Test in the console.
I did the following:
Installed Stash
Installed Pyperclip by running the command ‘pip install Pyperclip’ from within Stash. Package installed fine
Went back to console and ran the import Pyperclip command. No errors
However, when I try to run the function Pyperclip.copy() or .paste() I get an error:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/mobile/Containers/Shared/AppGroup/C6F5AC74-E13C-4A33-95BA-F075B9E680F9/Pythonista3/Documents/site-packages-3/pyperclip/__init__.py", line 120, in copy_osx_pbcopy
stdin=subprocess.PIPE, close_fds=True)
File "/var/containers/Bundle/Application/479FB713-67AD-4A41-9180-71A1C27C61E8/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/subprocess.py", line 708, in __init__
restore_signals, start_new_session)
File "/var/containers/Bundle/Application/479FB713-67AD-4A41-9180-71A1C27C61E8/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/subprocess.py", line 1261, in _execute_child
restore_signals, start_new_session, preexec_fn)
PermissionError: [Errno 1] Operation not permitted
I looked around for similar errors on stack overflow but the issues/ answers don’t seem to fit my situation. What am I doing wrong?

Pyperclip is not supported by Pythonista. Try their built in module, clipboard. http://omz-software.com/pythonista/docs/ios/clipboard.html

Related

Poppler is installed: why do I get an error using pdf2image on python3?

I am using python 3.7.4 on a macOS 10.14.6 and I am trying to use pdf2image to convert a pdf file into an image. So I have installed poppler with Homebrew. I get an error message when I try to convert the PDF.
Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/pdf2image/pdf2image.py", line 240, in _page_count
proc = Popen(command, env=env, stdout=PIPE, stderr=PIPE) File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 775, in __init__
restore_signals, start_new_session) File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 1522, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename) FileNotFoundError: [Errno 2] No such file or directory: 'pdfinfo': 'pdfinfo'
I use the following code:
from pdf2image import convert_from_path, convert_from_bytes
from pdf2image.exceptions import (
PDFInfoNotInstalledError,
PDFPageCountError,
PDFSyntaxError
)
images = convert_from_path('test.pdf')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/michelebutturini/Desktop/Segmentation.py", line 16, in <module>
images = convert_from_path('test.pdf')
File "/usr/local/lib/python3.7/site-packages/pdf2image/pdf2image.py", line 54, in convert_from_path
page_count = _page_count(pdf_path, userpw, poppler_path=poppler_path)
File "/usr/local/lib/python3.7/site-packages/pdf2image/pdf2image.py", line 244, in _page_count
raise PDFInfoNotInstalledError('Unable to get page count. Is poppler installed and in PATH?')
pdf2image.exceptions.PDFInfoNotInstalledError: Unable to get page count. Is poppler installed and in PATH?
I've had this problem on Google Colab and I've fixed with this command:
!apt-get install poppler-utils
I had a similar issue, and found my answer here:
https://github.com/Belval/pdf2image/issues/101
What SamikhaAgarwal said was:
"These pdf2image and pdftotext library backend requirement is Poppler, so you have to install
conda install -c conda-forge poppler
Then the error will be resolved, and if still it doesn't work for you, then you can follow http://blog.alivate.com.au/poppler-windows/ to install this library.
Maybe try:
brew install poppler
This worked for me.

Selenium using Python in 2019 on mac

I'm a non-programmer trying to use Automate the Boring Stuff with Python to do exactly that. I watched all the videos and thought I was ready, but as I tried to get going I'm stuck on square zero.
I'm on a Mac OSx Mojave Version 10.14.2
Successfully installed Python 3.7.2
I'm trying to follow this chapter: http://automatetheboringstuff.com/chapter11/
Successfully installed Selenium because:
import selenium
does not give an error.
but when I run this:
from selenium import webdriver
browser = webdriver.Firefox()
I get this error:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 76, in start
stdin=PIPE)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 775, in __init__
restore_signals, start_new_session)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 1522, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'your\\path\\geckodriver.exe': 'your\\path\\geckodriver.exe'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
driver = webdriver.Firefox(executable_path=r'your\path\geckodriver.exe')
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 164, in __init__
self.service.start()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 83, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'your\path\geckodriver.exe' executable needs to be in PATH.
>>> driver = webdriver.Firefox(executable_path=r'your\path\geckodriver.exe')
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 76, in start
stdin=PIPE)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 775, in __init__
restore_signals, start_new_session)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 1522, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'your\\path\\geckodriver.exe': 'your\\path\\geckodriver.exe'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
driver = webdriver.Firefox(executable_path=r'your\path\geckodriver.exe')
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 164, in __init__
self.service.start()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 83, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'your\path\geckodriver.exe' executable needs to be in PATH.
I've tried everything in this: Selenium using Python - Geckodriver executable needs to be in PATH and I don't think it works anymore.
I've installed geckodriver and tried appending it to PATH but nothing seems to work. geckodriver is installed in /usr/local/bin/ and I've appended it to path by running export PATH=$PATH:/path/to/geckodriver and export PATH=$PATH:/usr/local/bin/geckodriver but I keep getting the same error
I've tried having both the newest Firefox and Firefox v46 installed because I read somewhere that it doesn't work after that version.
Any help is much appreciated.
I suggest to install with pip
pip install geckodriver-autoinstaller
and then add this code
import geckodriver_autoinstaller
# Check if the current version of geckodriver exists
# and if it doesn't exist, download it automatically,
# then add geckodriver to path
geckodriver_autoinstaller.install()
Set your executable_path
from selenium import webdriver
webdriver.Firefox(executable_path=r'path\to\geckdriver\geckodriver.exe')
executable_path –
Full path to override which geckodriver binary to use for Firefox 47.0.1 and greater, which defaults to picking up the binary from the system path.
from documentation
Edit: also works on lower versions firefox
Edit 2:
Perhaps you could verify the executable can be found by python itself.
import os.path
os.path.exists(file_path)

openslide python import show:windows error

I am using python 2.7 win 32
I need to install openslide in python
in below page show
Install openslide
http://openslide.org/download/
which item download for windows.
i tried every thing.and pip installation
the error shows below
import openslide
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
import openslide
File "C:\Python27\lib\site-packages\openslide\__init__.py", line 29, in >>>> <module>
from openslide import lowlevel
File "C:\Python27\lib\site-packages\openslide\lowlevel.py", line 41, in <module>
_lib = cdll.LoadLibrary('libopenslide-0.dll')
File "C:\Python27\lib\ctypes\__init__.py", line 443, in LoadLibrary
return self._dlltype(name)
File "C:\Python27\lib\ctypes\__init__.py", line 365, in __init__
self._handle = _dlopen(self._name, mode)
WindowsError: [Error 126] The specified module could not be found
Thanks
This question may be old, but perhaps an answer will help a future viewer.
To fix this error, you need to download the openslide binaries at http://openslide.org/download/ look under (Windows Binaries)
Next, add the location of the bin folder to your system path (this will allow python to know where the module is). And that should solve the problem.
Install instructions found here: https://pypi.python.org/pypi/openslide-python

Error while opening subprocess python

I get this error while trying to open a txt. file. Please tell how to fix it .
code: subprocess.Popen("/home/yash/Documents/ct.txt")
time.sleep(1)
error:
Traceback (most recent call last):
File "/home/yash/Documents/final_downloader22.py", line 5, in <module>
subprocess.Popen("/home/yash/Documents/ct.txt")
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1259, in _execute_child
raise child_exception
OSError: [Errno 13] Permission denied
Text files are normally not executable. What do you mean with "open" here?
This could mean "open it so that I can use it in the program".
This works with file_object = open('/home/yash/Documents/ct.txt', 'r') and then using that file_object.
This as well could mean "let the file type's associated application open the file so that the user can edit it".
In this case, you would have to find out what the associated application is. How you do this is dependent on the OS you use as well as the window manager/desktop environment. It cannot be answered in a few short sentences.
You could use webbrowser module to open a text file for editing in a portable manner in a script:
import webbrowser
webbrowser.open("/home/yash/Documents/ct.txt")
From a command-line:
$ python -mwebbrowser "/home/yash/Documents/ct.txt"
See also patches for "Add shutil.open" Python issue.

Spyder IDE fails to start on Windows 10 with Python 3.8 [duplicate]

This question already has answers here:
Jupyter Notebook with Python 3.8 - NotImplementedError
(4 answers)
Closed 3 years ago.
Note: this issue is fixed in Spyder 4.1.3!
(original question) checking out Python 3.8 (x64) on Windows 10, I got into trouble when trying to setup Spyder. Note: the issue was reproducible with a fresh Python installation on a clean Windows-10 system. However, no such issues on Linux (tested on debian / Mint19.x).
At first, everything went smooth during installation via pip install spyder.
error #1: pywin32
After starting Spyder, it said in the IPython console window:
Traceback (most recent call last):
File "c:\users\USERNAME\appdata\local\programs\python\python38\lib\site‑packages\spyder\plugins\ipythonconsole.py", line 1572, in create_kernel_manager_and_kernel_client
kernel_manager.start_kernel(stderr=stderr_handle)
File "c:\users\USERNAME\appdata\local\programs\python\python38\lib\site‑packages\jupyter_client\manager.py", line 240, in start_kernel
self.write_connection_file()
File "c:\users\USERNAME\appdata\local\programs\python\python38\lib\site‑packages\jupyter_client\connect.py", line 470, in write_connection_file
self.connection_file, cfg = write_connection_file(self.connection_file,
File "c:\users\USERNAME\appdata\local\programs\python\python38\lib\site‑packages\jupyter_client\connect.py", line 141, in write_connection_file
with secure_write(fname) as f:
File "c:\users\USERNAME\appdata\local\programs\python\python38\lib\contextlib.py", line 113, in __enter__
return next(self.gen)
File "c:\users\USERNAME\appdata\local\programs\python\python38\lib\site‑packages\jupyter_core\paths.py", line 424, in secure_write
win32_restrict_file_to_user(fname)
File "c:\users\USERNAME\appdata\local\programs\python\python38\lib\site‑packages\jupyter_core\paths.py", line 359, in win32_restrict_file_to_user
import win32api
ImportError: DLL load failed while importing win32api: Das angegebene Modul wurde nicht gefunden.
I was able to fix the import error by running pywin32_postinstall.py -install from the scripts folder (from a cmd prompt with elevated rights). That copies pythoncom38.dll and pywintypes38.dll from \Lib\site-packages\pywin32_system32 to \windows\system32, see also here - however, I'd suggest to not modify system folders and use the option I put in my answer below.
error #2: tornado
However, now Spyder just freezes at the loading screen (logo displayed, saying something like "initializing main window")!
cloning the dev version of Spyder from https://github.com/spyder-ide/spyder.git and running it via python bootstrap.py --debug reveals the cause of the freeze:
2019-11-03 17:39:53,261 [ERROR] [tornado.application] -> Exception in callback functools.partial(<function ThreadedZMQSocketChannel.__init__.<locals>.setup_stream at 0x0000015E00B758B0>)
Traceback (most recent call last):
File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python38\lib\site-packages\tornado\ioloop.py", line 743, in _run_callback
ret = callback()
File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python38\lib\site-packages\jupyter_client\threaded.py", line 48, in setup_stream
self.stream = zmqstream.ZMQStream(self.socket, self.ioloop)
File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python38\lib\site-packages\zmq\eventloop\zmqstream.py", line 127, in __init__
self._init_io_state()
File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python38\lib\site-packages\zmq\eventloop\zmqstream.py", line 546, in _init_io_state
self.io_loop.add_handler(self.socket, self._handle_events, self.io_loop.READ)
File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python38\lib\site-packages\tornado\platform\asyncio.py", line 99, in add_handler
self.asyncio_loop.add_reader(fd, self._handle_events, fd, IOLoop.READ)
File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python38\lib\asyncio\events.py", line 501, in add_reader
raise NotImplementedError
NotImplementedError
...so it seems the import error caused by the Python 3.8 version of pywin32 is only one issue. There's also a problem related to tornado IO (web server), see here / here.
last checked with Python 3.8.2 (AMD64), Spyder 4.1.1. Please note that I am not using Anaconda. Use either conda or pip, not both.
Spyder 4.1.3 Update: The issue is fixed!
(Tested on Python 3.8.3rc1, tornado 6.0.4)
If you come here still experiencing similar startup issues with Spyder: the first thing to try I'd suggest upgrade to Spyder version >= 4.1.3.
older version of this answer
workaround, tornado issue:
Modify the file ...\Python38...\Lib\site-packages\tornado\platform\asyncio.py;
add
import sys
if sys.platform == 'win32':
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
after the other import statements. Source: here on SO and also linked here. If I get this post on the tornado repo right, this is likely to be a pretty permanent workaround.
if also needed - workaround, pywin32 issue:
Modify the file ...\Python38\Lib\site-packages\jupyter_core\path.py;
add a line
import pywintypes
before import win32api in line 359. This modification is based on this post.

Resources