eshangj/stackoverflow_q_and_a_sample huggingface dataset:
Question: The situation At work we have a private conda channel in our network that is used for some internal packages. Since I do not want to type the channel location every time I install something via conda install, I added it to condas default channels in .condarc. The problem Obviously the channel is only available inside my company's network. When I am outside the network and want to install for example numpy (so a normal package available on the conda default channel) I get the following error because the private channel is not available: conda.exceptions.UnavailableInvalidChannel: The channel is not accessible or is invalid. channel name: privateChannel channel url: file://address/in/companys/network error code: 404  independent from what package I want to install! What I am looking for An option to tell conda to ignore the UnavailableInvalidChannel error or something similar that solves my problem. Because I do not want to edit my .condarc every time I switch to another network... Usually I am aware of, if I am going to install an internal package that I need the company's channel for so I would not mind if conda skips the internal channel silently or with a warning for everything else if it is not available. I just do not want conda to abort everything if it is not available.  Another small related question: Is there a way to define channel aliases? I am aware of channel-alias but that just changes the default channel prefix.

Answer: Solution More or less by accident I found the answer to my own question recently and do not want to keep it by myself.  To prevent conda to fail when a channel is not available during install/update of packages from other available channels you have to set the following parameter in your .condarc file: allow_non_channel_urls = True  Or instead of editing your .condarc directly, you can type in your terminal: conda config --set allow_non_channel_urls True  The parameter with the not very intuitive name allow_non_channel_urls is not explained in the conda docs about using the .condarc conda configuration file. But you can find it in their full .condarc example here and nowhere else. What does it do? The official explanation is "Warn, but do not fail, when conda detects a channel url is not a valid channel". This means for example, that if the channel URL is simply not reachable from the network you are currently using (maybe you are outside of your companies network) conda will just print a warning instead of abort installing packages. This is exactly what I wanted! The warning can look quite excessive because it is printed for every architecture (linux-32, win-64, osx-64, noarch, etc.) Note Conda will still fail with an error if your package is not found on the available channels. But in that case you want conda to fail.
Question: Permanent deletion of an experiment isn't documented anywhere. I'm using Mlflow w/ backend postgres db Here's what I've run:  client = MlflowClient(tracking_uri=server) client.delete_experiment(1)  This deletes the the experiment, but when I run a new experiment with the same name as the one I just deleted, it will return this error: mlflow.exceptions.MlflowException: Cannot set a deleted experiment 'cross-sell' as the active experiment. You can restore the experiment, or permanently delete the experiment to create a new one.  I cannot find anywhere in the documentation that shows how to permanently delete everything.

Answer: Unfortunately it seems there is no way to do this via the UI or CLI at the moment :-/ The way to do it depends on the type of backend file store that you are using. Filestore: If you are using the filesystem as a storage mechanism (the default) then it is easy. The 'deleted' experiments are moved to a .trash folder. You just need to clear that out: rm -rf mlruns/.trash/*  As of the current version of the documentation (1.7.2), they remark:  It is recommended to use a cron job or an alternate workflow mechanism to clear .trash folder.  SQL Database: This is more tricky, as there are dependencies that need to be deleted. I am using MySQL, and these commands work for me: USE mlflow_db; # the name of your database DELETE FROM experiment_tags WHERE experiment_id=ANY( SELECT experiment_id FROM experiments where lifecycle_stage="deleted" ); DELETE FROM latest_metrics WHERE run_uuid=ANY( SELECT run_uuid FROM runs WHERE experiment_id=ANY( SELECT experiment_id FROM experiments where lifecycle_stage="deleted" ) ); DELETE FROM metrics WHERE run_uuid=ANY( SELECT run_uuid FROM runs WHERE experiment_id=ANY( SELECT experiment_id FROM experiments where lifecycle_stage="deleted" ) ); DELETE FROM tags WHERE run_uuid=ANY( SELECT run_uuid FROM runs WHERE experiment_id=ANY( SELECT experiment_id FROM experiments where lifecycle_stage="deleted" ) ); DELETE FROM runs WHERE experiment_id=ANY( SELECT experiment_id FROM experiments where lifecycle_stage="deleted" ); DELETE FROM experiments where lifecycle_stage="deleted";
Question: The code helped me download bunch of images from google. It used to work a few days back and now all of the sudden the code breaks.  Code :  # importing google_images_download module from google_images_download import google_images_download # creating object response = google_images_download.googleimagesdownload() search_queries = ['Apple', 'Orange', 'Grapes', 'water melon'] def downloadimages(query): # keywords is the search query # format is the image file format # limit is the number of images to be downloaded # print urs is to print the image file url # size is the image size which can # be specified manually ("large, medium, icon") # aspect ratio denotes the height width ratio # of images to download. ("tall, square, wide, panoramic") arguments = {"keywords": query, "format": "jpg", "limit":4, "print_urls":True, "size": "medium", "aspect_ratio": "panoramic"} try: response.download(arguments) # Handling File NotFound Error except FileNotFoundError: arguments = {"keywords": query, "format": "jpg", "limit":4, "print_urls":True, "size": "medium"} # Providing arguments for the searched query try: # Downloading the photos based # on the given arguments response.download(arguments) except: pass # Driver Code for query in search_queries: downloadimages(query) print()  Output log:  Item no.: 1 --> Item name = Apple Evaluating... Starting Download... Unfortunately all 4 could not be downloaded because some images were not downloadable. 0 is all we got for this search filter! Errors: 0 Item no.: 1 --> Item name = Orange Evaluating... Starting Download... Unfortunately all 4 could not be downloaded because some images were not downloadable. 0 is all we got for this search filter! Errors: 0 Item no.: 1 --> Item name = Grapes Evaluating... Starting Download... Unfortunately all 4 could not be downloaded because some images were not downloadable. 0 is all we got for this search filter! Errors: 0 Item no.: 1 --> Item name = water melon Evaluating... Starting Download... Unfortunately all 4 could not be downloaded because some images were not downloadable. 0 is all we got for this search filter! Errors: 0  This actually create a folder but no images in it. 

Answer: Indeed the issue has appeared not so long ago, there are already a bunch of similar Github issues:  https://github.com/hardikvasa/google-images-download/pull/298 https://github.com/hardikvasa/google-images-download/issues/301 https://github.com/hardikvasa/google-images-download/issues/302  Unfortunately, there is no official solution, for now, you could use the temporary solution that was provided in the discussions.
Question: I am currently trying to pip install tensorflow, which works but after I install it, and then import it into my python module via import tensorflow as tf I get following error message: ImportError: Could not find the DLL(s) 'msvcp140_1.dll'. TensorFlow requires that these DLLs be installed in a directory that is named in your %PATH% environment variable. You may install these DLLs by downloading "Microsoft C++ Redistributable for Visual Studio 2015, 2017 and 2019" for your platform from this URL: https://support.microsoft.com/help/2977003/the-latest-supported-visual-c-downloads  I installed the msvcp140_1.dll and put it into C:\Users\User\AppData\Local\Programs\Python\Python37 which is contained in my path environment variable. As you can see I am using Python 3.7 as 3.8 is not supported by tensorflow. Any ideas how to fix this?

Answer: You can find msvcp140.dll in your %windows%/System32 folder, once you installed VC++ DIST for VS 2015, for msvcp140_1.dll you need to goto this page https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads and in the section :Visual Studio 2015, 2017 and 2019, pick the correct package with the arch of your PC.
Question: I am trying to import fbprophet on Python Anaconda, however, I get this error:  ImportError: cannot import name 'easter' from 'holidays'  Can anyone suggest what might have gone wrong? Code: from fbprophet import fbprophet 

Answer: I'm using anaconda, and the only solution that worked for me was: Replace line 16 in fbprophet/hdays.py (\AppData\Local\Continuum\anaconda3\Lib\site-packages\fbprophet\hdays.py): from holidays import WEEKEND, HolidayBase, easter, rd  to from holidays import WEEKEND, HolidayBase from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd
Question: i'm trying to predict next customer purchase to my job. I followed a guide, but when i tried to use cross_val_score() function, it returns NaN values.Google Colab notebook screenshot Variables:   X_train is a dataframe X_test is a dataframe y_train is a list y_test is a list  Code: X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=50) X_train = X_train.reset_index(drop=True) X_train X_test = X_test.reset_index(drop=True) y_train = y_train.astype('float') y_test = y_test.astype('float') models = [] models.append(("LR",LogisticRegression())) models.append(("NB",GaussianNB())) models.append(("RF",RandomForestClassifier())) models.append(("SVC",SVC())) models.append(("Dtree",DecisionTreeClassifier())) models.append(("XGB",xgb.XGBClassifier())) models.append(("KNN",KNeighborsClassifier()))´ for name,model in models: kfold = KFold(n_splits=2, random_state=22) cv_result = cross_val_score(model,X_train,y_train, cv = kfold,scoring = "accuracy") print(name, cv_result) >> LR [nan nan] NB [nan nan] RF [nan nan] SVC [nan nan] Dtree [nan nan] XGB [nan nan] KNN [nan nan]  help me please!

Answer: Well thanks everyone for your answers. The answer of Anna helped me a lot!, but i don't used X_train.values, instead i assigned an unique ID to the Customers, then dropped Customers column and it works! Now the models has this output :) LR [0.73958333 0.74736842] NB [0.60416667 0.71578947] RF [0.80208333 0.82105263] SVC [0.79166667 0.77894737] Dtree [0.82291667 0.83157895] XGB [0.85416667 0.85263158] KNN [0.79166667 0.75789474]
Question: How can i solve this error. It will generate while running program. from bson import ObjectId class JSONEncoder(json.JSONEncoder): def default(self, o): if isinstance(o, ObjectId): return str(o) return json.JSONEncoder.default(self, o) 

Answer: That's most likely due to version mismatches. This worked for me: pip uninstall bson pip uninstall pymongo pip install pymongo
Question: To build a python project managed with poetry I need to build C extensions first (an equivalent to python setup.py build). poetry is able to do this according to this github issue. But to me it's not clear what to include into pyproject.toml that the C extension build is executed when building with poetry build?

Answer: Add build.py to the repo-root. E.g. if one has one header file directory and 2 source files: from distutils.command.build_ext import build_ext ext_modules = [ Extension("<module-path-imported-into-python>", include_dirs=["<header-file-directory>"], sources=["<source-file-0>", "<source-file-1>"], ), ] class BuildFailed(Exception): pass class ExtBuilder(build_ext): def run(self): try: build_ext.run(self) except (DistutilsPlatformError, FileNotFoundError): raise BuildFailed('File not found. Could not compile C extension.') def build_extension(self, ext): try: build_ext.build_extension(self, ext) except (CCompilerError, DistutilsExecError, DistutilsPlatformError, ValueError): raise BuildFailed('Could not compile C extension.') def build(setup_kwargs): """ This function is mandatory in order to build the extensions. """ setup_kwargs.update( {"ext_modules": ext_modules, "cmdclass": {"build_ext": ExtBuilder}} )  Add to pyproject.toml: [tool.poetry] build = "build.py"  To build the extension execute poetry build. For an example refer to this PR.
Question: I have this project where my base class and my sub-classes implement pydantic.BaseModel: from pydantic import BaseModel from typing import List from dataclasses import dataclass @dataclass class User(BaseModel): id: int @dataclass class FavoriteCar(User): car_names: List[str] car = FavoriteCar(id=1, car_names=["Acura"]) print(f"{car.id} {car.car_names[0]}")  But this error appears:  self.__fields_set__.add(name) E AttributeError: __fields_set__  Does someone mind explaining what is going on? The reason why I want to use pydantic is because I need a way to quickly convert Python objects to dict (or JSON) and back.

Answer: You need to decide whether to inherit from pydantic.BaseModel, or whether to use the @dataclass decorator (either from dataclasses, or from pydantic.dataclasses). Either is fine, but you cannot use both, according to the documentation (bold face added by myself):  If you don't want to use pydantic's BaseModel you can instead get the same data validation on standard dataclasses
Question: I am playing with examples from plotly.express piechart help page and trying to add an extra element iso_num to the hover_data property (iso_num is an int64 column in the gapminder dataframe) import plotly.express as px df = px.data.gapminder().query("year == 2007").query("continent == 'Americas'") fig = px.pie(df, values='pop', names='country', title='Population of American continent', hover_data=['lifeExp','iso_num'], labels={'lifeExp':'life expectancy','iso_num':'iso num' }) fig.update_traces(textposition='inside', textinfo='percent+label') fig.show()  Hovering over the slice of the pie chart then gives this:  where iso num value is %{customdata[1]} instead of the numeric value from the column.  What am I missing? Thanks!

Answer: This seems to be a relic from back when it was stated that  Oh pie hover is a big mess  Which since seems to be have been resolved. But perhaps not for px.pie()? I've tried numerous approaches, but I'm only able to get the customdata + hovertemplate approach to work for go.Pie and not for px.Pie. Here's a demonstration on how assigning values to customdata will make any variable otherwise not assigned to go.Pie() available for a custom hovertamplate: Plot:  Code: import plotly.graph_objects as go import plotly.express as px df = px.data.gapminder().query("year == 2007").query("continent == 'Americas'") fig = go.Figure(go.Pie( name = "", values = df['pop'], labels = df['country'], customdata=df['iso_num'], hovertemplate = "Country:%{label}: <br>Population: %{value} </br> iso num:%{customdata}" )) fig.show()
Question: In Python 3.6, there is the new f-string to include variables in strings which is great, but how do you correctly apply these strings to get super or subscripts printed for matplotlib? (to actually see the result with the subscript, you need to draw the variable foo on a matplotlib plot) In other words how do I get this behaviour:   var = 123 foo = r'text$_{%s}$' % var text<sub>123</sub>  Using the new f-string syntax? So far, I have tried using a raw-string literal combined with an f-string, but this only seems to apply the subscript to the first character of the variable:   var = 123 foo = fr'text$_{var}$' text<sub>1</sub>23  Because the { has an ambiguous function as delimiting what r should consider subscript and what f delimits as a place for the variable.

Answer: You need to escape the curly brackets by doubling them up, and then add in one more to use in the LaTeX formula. This gives: foo = f'text$_{{{var}}}$'  Example: plt.figure() plt.plot([1,2,3], [3,4,5]) var = 123 plt.text(1, 4,f'text$_{{{var}}}$')  Output:  Incidentally, in this example, you don't actually need to use a raw-string literal.
Question: I continuously get this error  UserWarning: WARN: Box bound precision lowered by casting to float32 warnings.warn(colorize('%s: %s'%('WARN', msg % args), 'yellow'))  when I start my training session. I guess it's coming from this line  self.action_space = spaces.Box(low, high)  The code is running but I want to stop this error from showing up I am using a cuda pc to run the code.

Answer: Explicitly specify the dtype as float32 in the call like so... self.action_space = spaces.Box(low, high, dtype=np.float32)  If that doesn't work, set the logger level lower in gym like so... import gym gym.logger.set_level(40)
Question: I have recently installed imblearn package in jupyter using  !pip show imbalanced-learn  But I am not able to import this package.  from tensorflow.keras import backend from imblearn.over_sampling import SMOTE  I get the following error --------------------------------------------------------------------------- ModuleNotFoundError Traceback (most recent call last) <ipython-input-20-f19c5a0e54af> in <module> 1 # from sklearn.utils import resample 2 from tensorflow.keras import backend ----> 3 from imblearn.over_sampling import SMOTE 4 5 ~/.virtualenvs/p3/lib/python3.6/site-packages/imblearn/__init__.py in <module> 32 Module which allowing to create pipeline with scikit-learn estimators. 33 """ ---> 34 from . import combine 35 from . import ensemble 36 from . import exceptions ~/.virtualenvs/p3/lib/python3.6/site-packages/imblearn/combine/__init__.py in <module> 3 """ 4 ----> 5 from ._smote_enn import SMOTEENN 6 from ._smote_tomek import SMOTETomek 7 ~/.virtualenvs/p3/lib/python3.6/site-packages/imblearn/combine/_smote_enn.py in <module> 8 from sklearn.utils import check_X_y 9 ---> 10 from ..base import BaseSampler 11 from ..over_sampling import SMOTE 12 from ..over_sampling.base import BaseOverSampler ~/.virtualenvs/p3/lib/python3.6/site-packages/imblearn/base.py in <module> 14 from sklearn.utils.multiclass import check_classification_targets 15 ---> 16 from .utils import check_sampling_strategy, check_target_type 17 18 ~/.virtualenvs/p3/lib/python3.6/site-packages/imblearn/utils/__init__.py in <module> 5 from ._docstring import Substitution 6 ----> 7 from ._validation import check_neighbors_object 8 from ._validation import check_target_type 9 from ._validation import check_sampling_strategy ~/.virtualenvs/p3/lib/python3.6/site-packages/imblearn/utils/_validation.py in <module> 11 12 from sklearn.base import clone ---> 13 from sklearn.neighbors._base import KNeighborsMixin 14 from sklearn.neighbors import NearestNeighbors 15 from sklearn.utils.multiclass import type_of_target ModuleNotFoundError: No module named 'sklearn.neighbors._base'  Other packages in the environment numpy==1.16.2 pandas==0.24.2 paramiko==2.1.1 matplotlib==2.2.4 scikit-learn==0.22.1 Keras==2.2.4 tensorflow==1.12.0 tensorboard==1.12.0 tensorflow-hub==0.4.0 xlrd==1.2.0 flask==1.0.2 wtforms==2.2.1 bs4==0.0.1 gensim==3.8.1 spacy==2.2.3 nltk==3.4.5 wordcloud==1.6.0 pymongo==3.10.1 imbalanced-learn==0.6.1  I checked the sklearn package, it contains base module, not _base. But modifying it may not be the right solution. Any other solution to fix this issue. 

Answer: Previous sklearn.neighbors.base has been renamed to sklearn.neighbors._base in version 0.22.1. You have probably a version of scikit-learn older than that. Installing the latest release solves the problem: pip install -U scikit-learn or pip install scikit-learn==0.22.1
Question: I have a query. I have seen examples where developers write something like the code as follows: import threading def do_something(): return true t = threading.Thread(target=do_something) t.start() t.join()  I know that join() signals the interpreter to wait till the thread is completely executed. But what if I do not write t.join()? Will the thread get closed automatically and will it be reused later? Please let me know the answer. It's my first attempt at creating a multi-threaded application in Python 3.5.0.

Answer: A Python thread is just a regular OS thread. If you don't join it, it still keeps running concurrently with the current thread. It will eventually die, when the target function completes or raises an exception. No such thing as "thread reuse" exists, once it's dead it rests in peace. Unless the thread is a "daemon thread" (via a constructor argument daemon or assigning the daemon property) it will be implicitly joined for before the program exits, otherwise, it is killed abruptly. One thing to remember when writing multithreading programs in Python, is that they only have limited use due to infamous Global interpreter lock. In short, using threads won't make your CPU-intensive program any faster. They can be useful only when you perform something involving waiting (e.g. you wait for certain file system event to happen in a thread).
Question: I have a very high resolution(3311, 4681, 3) image, which I want to show in my jupyter notebook using opencv but as other answers stated its not possible to use cv2.imshow in the jupyter notebook, so i used plt.imshow to do the same but the problem is I have to define the fig_size parameter if I want to display my image larger. How can I read the image in its original resolution in jupyter notebook or is it possible to open the image in another window? This is what I have tried :  import cv2 from matplotlib import pyplot as plt %matplotlib inline img = cv2.imread(r"0261b27431-07_D_01.jpg") plt.figure(figsize= (20,20)) plt.imshow(img) plt.show()   So basically I want my image to show in its original resolution in jupyter notebook or in another window.

Answer: You can imshow the image in its original resolution by calculating the corresponding figure size, which depends on the dpi (dots per inch) value of matplotlib. The default value is 100 dpi and is stored in matplotlib.rcParams['figure.dpi']. So imshowing the image like this import cv2 from matplotlib import pyplot as plt import matplotlib %matplotlib inline # Acquire default dots per inch value of matplotlib dpi = matplotlib.rcParams['figure.dpi'] img = cv2.imread(r'0261b27431-07_D_01.jpg') # Determine the figures size in inches to fit your image height, width, depth = img.shape figsize = width / float(dpi), height / float(dpi) plt.figure(figsize=figsize) plt.imshow(img) plt.show()  prints it in its large resolution, but with the drawback, that the axis labels are tiny compared to the large image. You can workaround this by setting other rcParams to larger values, e.g.  # Do the same also for the 'y' axis matplotlib.rcParams['xtick.labelsize'] = 50 matplotlib.rcParams['xtick.major.size'] = 15 matplotlib.rcParams['xtick.major.width'] = 5 ...   Your second suggestion to open the image in another window would work like this, that you change the matplotlib backend using Ipython magic commands by replacing %matplotlib inline in the above example with, e.g. %matplotlib qt # opens the image in an interactive window with original resolution  or  %matplotlib notebook # opens the image in an interactive window 'inline'  See here for more backend possibilites. Note that the calculation of the original figure size has to be done before also.