I'm trying to implement the answer here to suppress the chromedriver.exe prompt:
https://stackoverflow.com/a/39937466/264975
which tells me to use the following:
from win32process import CREATE_NO_WINDOW
However, I cannot get win32process module to load. I am told that it requires pypiwin32, however, there is no information on how to use these modules? For instance, what am I actually supposed to import and from where?
I successfully installed pypiwin32 using pip however, I have no idea how to verify it is working due to the lack of help files.
Would be grateful for some pointers as to how to get the example working.
Does it matter that im on a 64 bit pc? I think the python I am using is 32 bit though.
Was trying to do the same thing.
Am on a Windows 10 64-bit machine using Python 2.7.
Kept on saying win32process not found.
I installed a bunch of different modules and a few command line install commands, but what got it working was after I installed this exe package pywin32-221.win-amd64-py2.7.exe from https://sourceforge.net/projects/pywin32/files/pywin32/
Then as https://stackoverflow.com/a/39937466/264975 instructs go to your Python folder, then
Lib\site-packages\selenium\webdriver\common\
and edit service.py (in the thread it mentions services.py but this is what was in my folder)
And include from win32process import CREATE_NO_WINDOW at the top of this script. Mine looks like this
import errno
import os
import platform
import subprocess
from subprocess import PIPE
from win32process import CREATE_NO_WINDOW
import time
from selenium.common.exceptions import WebDriverException
from selenium.webdriver.common import utils
then further down in this script look for def start(self):, and just add this to the end of self.process =
creationflags=CREATE_NO_WINDOW
So mine looks like this
self.process = subprocess.Popen(cmd, env=self.env,
close_fds=platform.system() != 'Windows',
stdout=self.log_file,
stderr=self.log_file,
stdin=PIPE,
creationflags=CREATE_NO_WINDOW)
That's all. Now the chromedriver.exe console does not pop-up at all in my python scripts.
That's what worked for me. Hard to say if it was a number of things together that made it work or just by installing the pywin32-amd64.exe package.
Related
In a project I need to import RLock from threading module in Python3.6
But no matter what I do, I still have the same error :
from threading import RLock
ImportError: cannot import name 'RLock'
Each time I want to import this module (threading) I have this error.
I already upgraded pip, but it doesn't work.
If someone has a solution for me I would be very grateful.
Edit
This error doesn't depend on the folder in which I am located. I notice that when I am running the command in Python2.7 :
import threading
It works.
But if I am running this command under Python3.6 it doesn't work, still with the same output error.
I checked and the only threading.py files I have are :
/snap/core/6673/usr/lib/python3.5/threading.py
/snap/core/6818/usr/lib/python3.5/threading.py
/snap/core/6964/usr/lib/python3.5/threading.py
/snap/core18/941/usr/lib/python3.6/threading.py
/snap/core18/970/usr/lib/python3.6/threading.py
/snap/docker/384/usr/lib/python2.7/threading.py
/snap/docker/384/usr/lib/python3.5/threading.py
/snap/gnome-3-26-1604/74/usr/lib/python3.5/threading.py
/snap/gnome-3-26-1604/82/usr/lib/python3.5/threading.py
/snap/gnome-3-28-1804/36/usr/lib/python3.6/threading.py
/snap/gnome-3-28-1804/40/usr/lib/python3.6/threading.py
/snap/libxml2/69/usr/lib/python2.7/threading.py
/usr/lib/python2.7/threading.py
/usr/lib/python2.7/threading.pyc
/usr/lib/python3.6/threading.py
/usr/lib/python3.7/threading.py
I think you have a Python file which called threading. You should rename your file and the import will work. I have just tried it with Python3.6.6 and it works as expected.
Code
from threading import RLock
rl = RLock()
print(rl)
Output:
>>>python other.py
<_RLock owner=None count=0>
I found the origin of the problem by looking at the complete error logs (which I should have specified here, I apologize). Turns out I have a file named token.py. By renaming it the error disappears.
Thank you for your answers.
I'm trying to run CairoSVG but I don't have permission on the server to run it. No problem I think, I've used other libraries in Python before without installing them by pointing sys.path.append to their directory path:
import sys
sys.path.append("/full/path/to/SomeOtherLibrary")
import SomeOtherLibrary
I thought I could create something like loader.py, import the path inside there to CairoSVG with a sys.path.append, then instead of calling: cairosvg image.svg -o image.png I could call /full/path/to/loader.py image.svg -o image.png.
Then I started to create loader.py and thought I have no idea what to do or if this is even possible. I figured I start with:
import sys
sys.path.append("/full/path/to/CairoSVG")
And then I don't know what. If I was able to install the script I'd need to pass parameters to it. How can I create a loader to run this library?
Simply call cairosvg.main() from your script. Pretty much like it is done here: https://github.com/Kozea/CairoSVG/blob/master/cairosvg.py
I am want to transform a hive table (hdfs spot instances) using a Python UDF for which I need an external library "user-agents". My udf without the use of external library is working fine. But I am not able to get things working when I want to use it.
I tried installing the library using the code itself given below.
import sys
import subprocess
import pip
import os
sys.stdout = open(os.devnull, 'w+')
pip.main(['install', '--user', 'pyyaml'])
pip.main(['install', '--user', 'ua-parser'])
pip.main(['install', '--user', 'user-agents'])
sys.stdout = sys.__stdout__
and after this I tried this
import user_agents
but the udf is crashing with an exception "No module found". I also tried checking the following paths through code :
/usr/local/lib/python2.7/site-packages
/usr/local/lib64/python2.7/site-packages
But no user_agents module was there. Any help on how to do it to get things working ? Would really appreciate it. Thanks !
I figured a way out of this. For those who are solving this same UDF issue and are not successful yet can possibly try this solution and check if it works for them too.
For external libraries, do the following steps:
Step 1: Force pip to install the external library through code itself to the current working directory of your UDF.
import sys
import os
import pip
sys.stdout = open(os.devnull, 'w+')
pip.main(['install', 'user-agents', '-t', os.getcwd(), '--ignore-installed'])
sys.stdout = sys.__stdout__
Step 2: Update your sys.path
sys.path.append(os.getcwd())
Step 3: Now import the library :)
from user_agents import parse
That's it. Please check and confirm it this works for you too.
I am trying to set up IBPY and Python on my Mac to run with Interactive Brokers. I have installed Git. I created a subdirectory ibapi under Home. I downloaded IBPy using git clone https://github.com/blampe/IbPy from the ibapi directory.
I am now trying to run the Demo.py program in Spyder. When I choose Run, I receive the error message:
ImportError: No module named Ib.Message
The first few lines of the demo program are:
import os
import sys
import time
import Ib.Message
import Ib.Socket
import Ib.Type
I am also trying to run a sample program: ib_api_demo from http://www.quantstart.com/articles/Using-Python-IBPy-and-the-Interactive-Brokers-API-to-Automate-Trades. When I try to run this, I get the error message:
ImportError: No module named ib.ext.Contract
The first few lines are:
from ib.ext.Contract import Contract
from ib.ext.Order import Order
from ib.opt import Connection, message
I figured this out. The problem was I was launching Spyder from my Mac Finder. When I did this, I received the error messages. When I launched Spyder (actually Anaconda Python) by typing "Spyder" in the Terminal window, this launched Anaconda Python. From here, I could run all my programs successfully with no errors.
My goal is to create a python script that loops over cells of an excel document. This is my python script called reader.py, and it works just fine.
import xlrd
import os
exceldoc = raw_input("Enter the path to the doc [C:\\folder\\file.xlsx]: ")
wb = xlrd.open_workbook(exceldoc,'rb')
.... some code....
The problem I'm encountering is attempting to use py2exe to create an executable so this script can be used elsewhere.
Here is my setup.py file:
from distutils.core import setup
import py2exe
import sys
from glob import glob
setup(name='Excel Document Checker',console=['reader.py'])
I run the following command: python setup.py py2exe
It appears to run fine; it creates the dist folder that has my reader.exe file, but near the end of the command I get the following:
The following modules appear to be missing
['cElementTree', 'elementtree.ElementTree']
I did some searching online, and tried the recommendations here Re: Error: Element Tree not found, this changing my setup.py file:
from distutils.core import setup
import py2exe
import sys
from glob import glob
options={
"py2exe":{"unbuffered": True,"optimize": 2,
'includes':['xml.etree.ElementPath', 'xml.etree.ElementTree', 'xml.etree.cElementTree'],
"packages": ["elementtree", "xml"]}}
setup(name='Excel Document Checker',options = options,console=['reader.py'])
I'm now getting an error:
ImportError: No module named elementtree
I'm sort of at an impasse here. Any help or guidance is greatly appreciate.
Just some information - I'm running Python 2.6 on a 32 bit system.
You explicitly told setup.py to depend on a package named elementtree here:
"packages": ["elementtree", "xml"]}}
There is no such package in the stdlib. There's xml.etree, but obviously that's the same name.
The example you found is apparently designed for someone who has installed the third-party package elementtree, which is necessary if you need features added after Python 2.6's version of xml.etree, or if you need to work with Python 1.5-2.4, but not if you just want to use Python 2.6's version. (And anyway, if you do need the third-party package… then you have to install it or it won't work, obviously.)
So, just don't do that, and that error will go away.
Also, if your code—or the code you import (e.g., xlrd) is using xml.etree.cElementTree, then, as the py2exe FAQ says, you must also import xml.etree.ElementTree before using it to get it working. (And you also may need to specify it manually as a dependency.)
You presumably don't want to change all the third-party modules you're using… but I believe that making sure to import xml.etree.ElementTree before importing any of those third-party modules works fine.