Questions tagged [python]
Python is a dynamically typed, multi-purpose programming language. It is designed to be quick to learn, understand, and use, and enforces a clean and uniform syntax. Note that Python 2 reached end-of-life on January 1st, 2020. For version-specific Python questions, add the version tag (e.g. [python-3.x] or [python-3.9]). When using a Python variant (e.g. Jython, PyPy) or library (e.g. Pandas, NumPy), please include it in the tags.
python
641,961
questions with no upvoted or accepted answers
29
votes
1
answer
2k
views
Graph optimizations on a tensorflow serveable created using tf.Estimator
Context:
I have a simple classifier based on tf.estimator.DNNClassifier that takes text and output probabilities over an intent tags. I am able to train an export the model to a serveable as well as ...
23
votes
1
answer
2k
views
xgboost.plot_tree: binary feature interpretation
I've built an XGBoost model and seek to examine the individual estimators. For reference, this was a binary classification task with discrete and continuous input features. The input feature matrix is ...
20
votes
0
answers
3k
views
Resolving differences between Keras and scikit-learn for simple fully-connected neural network
I have built a fully-connected neural network in both scikit-learn (v 0.20.0) and Keras (v 2.2.4) with TensorFlow backend (v 1.12.0). There are 10 units in the single hidden layer. In both cases I ...
20
votes
2
answers
3k
views
FastCGI, Lighttpd, and Flask
I'm setting up a simple web server on my Raspberry Pi and I can't seem to set up lighttpd, fastcgi, and flask correctly.
By now, I've gone through a few iterations of /etc/lighttpd/lighttpd.conf, the ...
20
votes
3
answers
10k
views
Nested cross-validation example on Scikit-learn
I'm trying to work my head around the example of Nested vs. Non-Nested CV in Sklearn. I checked multiple answers but I am still confused on the example.
To my knowledge, a nested CV aims to use a ...
19
votes
6
answers
2k
views
How to configure VS Code's Integrated Terminal to use the correct Python Interpreter
TL;DR
This question is NOT asking how to select a Python Interpreter to run, or debug, code with, furthermore; this question is NOT asking anything in regard to Virtual Environment, or how to activate ...
19
votes
0
answers
2k
views
Create a QEMU Bridge Using the Socket Networking Backend
I am trying to create a bridge to an interface in my host, much like the Virtualbox's and VMWare's bridge adapters, in QEMU, using a combination of socket networking and a Python library called Scapy (...
19
votes
1
answer
1k
views
Mutation for nested object
I'm trying to implement GraphQL mutation for a "complex" object. Let's say we have a Contact with three fields: firstName, lastName and address, which is object with one field street:
Here ...
18
votes
1
answer
16k
views
Connect to sql server from linux environment using putty private key, sqlalchemy and pyodbc
Hi I am trying to read a dataframe from sql server from a linux(ubuntu server).
The file(gscm.ppk) has the admin keys in it
I have used the following format to connect to sql server:
import urllib....
18
votes
5
answers
16k
views
Install from pipfile using pipenv install gives error
I have a project where I'm trying to install from the pipfile using pipenv install. I get som error when installing. Before i describe the error, this is what I did:
Reinstall pipenv
Reinstall Python ...
18
votes
0
answers
1k
views
robobrowser won't change cookies
I have a POST request sent to server from robobrowser, and the server responds with no data. The response headers are as follows (this is the response from Chrome browser and it's the way it supposed ...
18
votes
1
answer
2k
views
Saving multiple images in MayaVi
I want to render around 500 images and save them to different png files, therefore I wrote a small class which contains my dataset and a renderfunction
from mayavi import mlab
mlab.options.offscreen=...
18
votes
5
answers
10k
views
How to print value of tensorflow.python.framework.ops.Tensor in Tensorflow 2.0?
I have a few tensors in my code and and need to get the values of those tensors. This is one them. How to print the values of tensor OA?
Input:OA
Output: <tf.Tensor 'Sum_1:0' shape=(1, 600) dtype=...
17
votes
0
answers
6k
views
Reprojecting .tiff file with rasterio: CRSError: The WKT could not be parsed. OGR Error code 6
I am trying to re-projected a .tiff file to EPSG:32638 with the following code.
Versions I have installed:
Rasterio version 1.1.5
Numpy version 1.18.1
This is the code I am using:https://rasterio....
17
votes
0
answers
2k
views
How to test rollbacks in SQLAlchemy
I have a problem with test isolation when testing a logic, that involves a transaction rollback in SQLAlchemy.
Model:
class Product(db.Model):
id = db.Column(db.Integer, primary_key=True)
...
17
votes
1
answer
14k
views
Place to initialize DB in Flask
I'm developing app in Flask and it requires DB, so what I have is I do:
app = Flask(__name__)
@app.before_request
def init_db_connection:
# here I connect to my DB
@app.teardown_request
def ...
17
votes
2
answers
7k
views
How to Configure Poetry Environments in Pycharm With Windows + WSL2?
TL;DR: can't configure a Python Interpreter on PyCharm (Windows) using an existing Poetry environment in WSL. When trying to set the Poetry environment path under Add Python Interpreter > Poetry ...
16
votes
0
answers
5k
views
VS code with Jupyter notebook is extremely slow when re-running cells
I’ve got trouble with Jupyter in vscode. On vs code start-up, my 10 cells “run all” in about 3-4 minutes in a perfectly sensible way (loading the data and heavy calculations take time, but plotting is ...
16
votes
2
answers
8k
views
'ImportError: No module named ...' when trying to import pyx file to Jupyter
I have this file em.pyx in the same folder as the Jupyter notebook where I try to import it but it is giving me the error
ImportError: No module named em
I've tried adding
import sys
sys.path....
16
votes
1
answer
2k
views
LSTM object detection tensorflow
Long story short:
How to prepare data for lstm object detection retraining of the tensorflow master github implementation.
Long story:
Hi all,
I recently found implementation a lstm object ...
16
votes
1
answer
22k
views
Python3 importlib.util.spec_from_file_location with relative path?
There are a lot of python questions about how to import relative packages or by explicit location (linked to two popular examples).
In addition there is always the documentation
Having read this, I ...
16
votes
1
answer
3k
views
ProgrammingError: column "X" is of type double precision but expression is of type numeric[]
I am trying to program an API with Django Rest Framework and Psycopg2 library. This API works with PostgreSQL database. I need to store 2 float array fields in this db because the API works with 2 ...
16
votes
2
answers
10k
views
How does autoreload work with jupyter?
I have a file mytest.py in the working directory, with the following content:
class MyTest(object):
def __init__(self):
print(1)
pass
In jupyter I have these cells.
Cell 1:
%reload_ext ...
16
votes
3
answers
3k
views
User defined generic types and collections.abc
I have a Python package that defines a variety of collections based on the ABCs provided by collections.abc (Mapping, Sequence, etc). I want to take advantage of the type hinting facilities introduced ...
16
votes
1
answer
14k
views
Gunicorn With Gevent, Performance Gain
Gunicorn Worker Class
Gunicorn has worker_class setting. Some possible values are
sync
gthread
gevent
Definitions from Luis Sena's nice blog
sync
This is the default worker class. Each process will ...
16
votes
3
answers
20k
views
Is there a way to restart or reset the python interpreter within a python doctest?
I am writing a short tutorial, and would like to be able to run the examples therein using python's doctest using
python -m doctest foo.txt
There is a point in the tutorial at which I want to start ...
15
votes
1
answer
11k
views
Ignore pkg_resources.ContextualVersionConflict or ResolutionImpossible
I have built a python module which installs kwikapi==0.4.5 and requests==2.22.0. But kwikapi has requests==2.18.4.
Now when I install and run my package, I am getting error pkg_resources....
15
votes
2
answers
11k
views
How do I use a GitHub access token with GitPython?
I am trying to write a python script that when run, will push files to one of my GitHub repositories. I'm using the package GitPython. I want to use an access token to log in into my GitHub account (...
15
votes
1
answer
1k
views
Flask SERVER_NAME setting best pratices
Since my app has background tasks, I use the Flask context. For the context to work, the Flask setting SERVER_NAME should be set.
When the SERVER_NAME is set the incoming requests are checked to match ...
15
votes
0
answers
1k
views
matplotlib with pgf, error: dimension too large
In using the pgf backend of matplotlib, I sometimes see an error like this:
! Dimension too large.
<to be read again>
\advance
l.69 ...o{\pgfqpoint{-11.400000in}{-235....
14
votes
0
answers
4k
views
How can I find out which symbol is causing "dyld: missing symbol called"?
On MacOS, I have a set of python binaries I don't control (i.e. I can't build them with LDFLAGS='-undefined error').
On certain MacOS hosts/architectures (that is, some ARM Macs, but not all of them; ...
14
votes
0
answers
730
views
Pickle still fails for numpy.void objects
Over a year ago I reported a bug I encountered while pickling some fairly complex data. At the time I didn't know what the issue was and believed it might have had something todo with recursive ...
14
votes
1
answer
6k
views
Is .NET Core or .NET 5.0 supported by Pythonnet
I've been using Pythonnet for quite some time but always against .NET Framework 4.*
With the recent release of .NET 5.0 I wanted to migrate my projects but I could not make it work for non-Framework ...
14
votes
1
answer
3k
views
How to use a CRF layer in Tensorflow 2 (using tfa.text)?
model= Sequential()
model.add(keras.layers.Embedding(vocab_size,output_dim=100,input_length=input_len,weights=[embedding_matrix],trainable=False))
model.add(keras.layers.Bidirectional(keras.layers....
14
votes
2
answers
1k
views
Airflow - Different schedule interval for backfilling
What's the best way to handle having a different schedule interval for backfilling and ongoing running?
For backfilling I want to use a daily interval, but for ongoing running I want to use an hourly ...
14
votes
3
answers
3k
views
SQLAlchemy: What is the best way to validate a model before inserting or updating
I'm trying to validate a SQLAlchemy model before it is inserted or updated, e.g
class MyModel(db.Model):
foo = db.Column(db.String(255))
bar = db.Column(db.String(255))
I've tried a few ...
14
votes
2
answers
1k
views
OperationalError: (sqlite3.OperationalError) too many SQL variables, while using SQL with dataframes
I have a pandas dataframe as below.
activity User_Id \
0 VIEWED MOVIE 158d292ec18a49
1 VIEWED MOVIE 158d292ec18a49
2 VIEWED MOVIE 158d292ec18a49
3 VIEWED MOVIE ...
14
votes
1
answer
1k
views
Block jupyter notebook cell execution till specific message received
I'm trying to implement asynchronous, distributed computation engine for python, which is compatible with jupyter notebook. The system is supposed to be based on 'push notification' approach what ...
14
votes
1
answer
431
views
Openface Flask Wrapper: Flask seems to be blocking a thread
I am trying to write a small flask REST API wrapper around the openface api so that I can POST image URLs to my flask server and have it run a comparison of the image against a classifier model
app = ...
14
votes
1
answer
3k
views
uwsgi segmentation fault when using flask and python requests
I'm running a dev uwsgi server using flask and a call to requests.get is triggering a segmentation fault in the uWSGI process.
Segmentation Fault:
!!! uWSGI process 70490 got Segmentation Fault !!!
*...
14
votes
1
answer
747
views
Flask: How to detect disconnection in infinite response generator?
In flask I have a page that is used with EventSource to receive updates/events.
It's implemented in fairly trivial manner:
@route('/updates')
def updates():
def gen():
while True:
...
14
votes
2
answers
4k
views
Resource corpora/wordnet not found (running quepy dbpedia example app)
I have scoured the web (including the 6 links that show similar problems with Heroku, Anaconda etc but common root cause - resource corpora/wordnet not found) and performed all that I could which ...
14
votes
1
answer
9k
views
sphinx-apidoc usage - multiple source python directories
So I have my python source files in two different directories:-
e.g.
~/work/myproject
~/.virtualenvs/myproject
How do I use sphinx-apidoc to look in both directories recursively to generate my reST ...
14
votes
1
answer
3k
views
Correctly Scraping and Displaying Japanese Characters using Python Django BeautifulSoup and Curl
I'm trying to scrape a page in japanese using python, curl, and BeautifulSoup. I then save the text to a MySQL database that's using utf-8 encoding, and display the resulting data using Django.
Here ...
14
votes
5
answers
12k
views
Selenium-ChromeDriver SSL error/handshake failed
My script is throwing a ton of SSL errors as below:
[19852:2032:0912/202419:ERROR:ssl_client_socket_impl.cc(1141)] handshake failed;
returned -1, SSL error code 1, net_error -100
[19852:2032:0912/...
14
votes
1
answer
2k
views
Why does unittest require __init__.py to be present in Python 3.6?
I just come across this line in python3.6 unittest (/usr/lib/python3.6/unittest/loader.py:286):
is_not_importable = not os.path.isfile(os.path.join(start_dir, '__init__.py'))
which caused the ...
13
votes
4
answers
22k
views
ERROR Backend subproccess exited when trying to invoke get_requires_for_build_sdist
I used the Upload Python Package workflow on GitHub to upload the module stored in the repository to PyPI.
As you can see at the link above, I followed the tutorial given by packaging.python.org, to ...
13
votes
1
answer
5k
views
Grpc not increasing max size of the message: received message larger than max
I am using grpc to send some pretty large messages (the parameters of a machine learning model over the network). The problem is that I am getting the following error when I make a grpc call:
grpc: ...
13
votes
0
answers
18k
views
Use of pre-commit with PyCharm
I am trying to launch my pre-commit hooks from "commit" button in PyCharm (v. 2020.2).
I use a conda venv (created with conda create -n py38 python=3.8) where I installed modules with pip ...
13
votes
3
answers
1k
views
How to save mobile screenshot using Headless Google Chrome with Selenium
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--disable-gpu')
mobile_emulation = {
"deviceMetrics&...