Posts

Showing posts with the label python

cannot import name '_endpoint_from_view_func' from 'flask.helpers' in python

7 I ran the same code on Ubuntu with no problem, but ran it on Windows10 with problems. I also installed Flask. My windows environment is configured as follows: $ pip --version pip 21.1.1 from c:\users\min\appdata\local\programs\python\python37\lib\site-packages\pip (python 3.7) $ pip show flask Name: Flask Version: 2.0.0 Summary: A simple framework for building complex web applications. Home-page: https://palletsprojects.com/p/flask Author: Armin Ronacher Author-email: armin.ronacher@active-4.com License: BSD-3-Clause Location: c:\users\min\appdata\local\programs\python\python37\lib\site-packages Requires: Werkzeug, itsdangerous, Jinja2, click Required-by: Flask-RESTful, Flask-API $ pip show flask-restful Name: Flask-RESTful Version: 0.3.8 Summary: Simple framework ...

Gunicorn ImportError: cannot import name 'ALREADY_HANDLED' from 'eventlet.wsgi' in docker

7 1 I had a working code running flask with gunicorn (eventlet worker) in docker. It's also working in production, but on my machine, it started doing this. I can't find anything on google about this thing. What meight be the problem? Error: class uri 'eventlet' invalid or not found: web_1 | web_1 | [Traceback (most recent call last): web_1 | File "/root/.local/lib/python3.7/site-packages/gunicorn/util.py", line 99, in load_class web_1 | mod = importlib.import_module('.'.join(components)) web_1 | File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module web_1 | return _bootstrap._gcd_import(name[level:], package, level) web_1 | File "<froz...

Pip 21.1 can't import InvalidSchemeCombination

13 At work, we use Github actions to build and test our Pull Requests before they can be approved. On Friday afternoon, everything was working just fine. On Monday morning, all tests were failing pretty early, with an error showing that pip could no longer find its own exceptions. Did something change with the newest Pip? As you can see in the errors below, our own code isn't referenced, and I'm fairly certain nothing in our flow changed between Friday and Monday (we're a small team and the approved PRs don't have anything surprising there). Error Traceback: Traceback (most recent call last): File "/opt/hostedtoolcache/Python/3.7.9/x64/bin/pip", line 5, in <module> from pip._internal.cli.main import main File "/opt/h...

Why is the GNU scientific library matrix multiplication slower than numpy.matmul?

12 2 Why is it that the matrix multiplication with Numpy is much faster than gsl_blas_sgemm from GSL, for instance: import numpy as np import time N = 1000 M = np.zeros(shape=(N, N), dtype=np.float) for i in range(N): for j in range(N): M[i, j] = 0.23 + 100*i + j tic = time.time() np.matmul(M, M) toc = time.time() print(toc - tic) gives something between 0.017 - 0.019 seconds, while in C++: #include <chrono> #include <iostream> #include <gsl/gsl_matrix.h> #include <gsl/gsl_blas.h> using namespace std::chrono; int main(void) { int N = 1000; gsl_matrix_float* M = gsl_matrix_float_alloc(N, N); for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { gsl_matrix_float_set(M, i, j, 0.23 ...

What is the most efficient way of getting the intersection of k sorted arrays?

6 2 Given k sorted arrays what is the most efficient way of getting the intersection of these lists Ex INPUT: [[1,3,5,7], [1,1,3,5,7], [1,4,7,9]] Output: [1,7] There is a way to get the union of k sorted arrays based on what I read in the Elements of programming interviews book in nlogk time. I was wondering if there is a way to do something similar for the intersection as well ## merge sorted arrays in nlogk time [ regular appending and merging is nlogn time ] import heapq def mergeArys(srtd_arys): heap = [] srtd_iters = [iter(x) for x in srtd_arys] # put the first element from each srtd array onto the heap for idx, it in enumerate(srtd_iters): elem = next(it, None) if elem: heapq.heappush(heap, (elem, idx)) ...

Django 3.2 exception: django.core.exceptions.ImproperlyConfigured

3 1 I'm upgrading to django 3.2 but as per it's release notes, it says: The SECRET_KEY setting is now checked for a valid value upon first access, rather than when settings are first loaded. This enables running management commands that do not rely on the SECRET_KEY without needing to provide a value. As a consequence of this, calling configure() without providing a valid SECRET_KEY, and then going on to access settings.SECRET_KEY will now raise an ImproperlyConfigured exception. Error: django.core.exceptions.ImproperlyConfigured: Cannot import 'users'. Check that 'apps.users.apps.UsersConfig.name' is correct. Users apps.py: from django.apps import AppConfig class UsersConfig(AppConfig): name = 'users' I think that error is be...

Discord Attachments Link

1 Well if you would like to get the attachments from a Discord message, you can do it by the following way: attachements = message.attachments But it cannot get attachments which are sent with a link. Like the following links: https://media.discordapp.net/attachments/722437402685341766/801262293693890580/banner.gif https://cdn.discordapp.com/attachments/281595941746900992/710992416039108748/unknown.png(I got it from a spam report) They already have a different starting url. How to extract them from the message? python python-3.x discord.py re Share ...

Why am I getting this Index out of range error?

4 I am a beginner at Python, and I was writing some code that would pick a random letter from a list, print it, then delete it from the list so it would not be picked again. The cycle repeats through a while loop. import random list = ["a", "b", "c", "d", "e", "f", "g", "h" , "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"] yn = "y" while yn == "y": npat = random.randint(0, 25) print(list[npat]) del list[npat] yn = input("Again?: ") It ...

pycharm WARNING: Value for scheme.headers does not match [duplicate]

3 This question already has answers here : “WARNING: Value for scheme.data does not match” when I try to update pip or install packages (5 answers) Closed 6 days ago . https://i.stack.imgur.com/Us1wC.png Hello after updating the pip it gave this error. How is it solved? WARNING: Value for scheme.headers does not match. Please report this to <https://github.com/pypa/pip/issues/9617...

How to add 91 to all the values in a column of a pandas data frame?

2 Consider my data frame as like this S.no Phone Number 1 9955290232 2 8752837492 3 9342832245 4 919485928837 5 917482482938 6 98273642733 I want the values in "Phone number" column to prefixed with 91 If the value has 91 already then, proceed to the next value. My output S.no Phone Number 1 919955290232 2 918752837492 3 919342832245 4 919485928837 5 917482482938 6 919827364273 How could this be done? python pandas dataframe numpy Share ...

Convert lines of string to a dictionary

3 I have an initial code like this: record = "Jane,Doe,25/02/2002; James,Poe,19/03/1998; Max,Soe,16/12/2001 ..." I need to make it into a dictionary and its output should be something like this: {'First name': 'Jane', 'Last name': 'Doe', 'Birthday': '25/02/2002'} {'First name': 'James', 'Last name': 'Poe', 'Birthday': '19/03/1998'} ... Each line should have an incrementing key starting from 1. I currently have no idea to approach this issue as I am still a student with no prior experience. I have seen people use this for strings containing key-value pairs but my string does not contain those: mydict = dict((k.strip(), v.strip()) ...

how to get a subgroup start finish indexes of dataframe

5 1 df=pd.DataFrame({"C1":['USA','USA','USA','USA','USA','JAPAN','JAPAN','JAPAN','USA','USA'],'C2':['A','B','A','A','A','A','A','A','B','A']}) C1 C2 0 USA A 1 USA B 2 USA A 3 USA A 4 USA A 5 JAPAN A 6 JAPAN A 7 JAPAN A 8 USA B 9 USA A This is a watered version of my problem so to keep it simple, my objective is to iterate a sub group of the dataframe where C2 has B in it. If a B is in C2 - I look at C1 and need the entire group. So in this example, I see USA and it starts at index 0 and finish at 4. Another one is between 8 and 9. ...