‘Import “Path.to.own.script” could not be resolved Pylance (reportMissingImports)’ in VS Code using Python 3.x on Ubuntu 20.04 LTS

Pylance, by default, includes the root path of your workspace. If you want to include other subdirectories as import resolution paths, you can add them using the python.analysis.extraPaths setting for the workspace. In VS Code press <ctrl> + <,> to open Settings. Type in python.analysis.extraPaths Select “Add Item” Type in the path to your library … Read more

SKLearn warning “valid feature names” in version 1.0

I got the same warning message with another sklearn model. I realized that it was showing up because I fitted the model with a data in a dataframe, and then used only the values to predict. From the moment I fixed that, the warning disappeared. Here is an example: model_reg.fit(scaled_x_train, y_train[vp].values) data_pred = model_reg.predict(scaled_x_test.values) This … Read more

pip throws “TypeError: deprecated() ” error

Something got broken down in OpenSSL and no command was working with pip afterwards. I was even unable uninstall pip. I removed installation files manually (most likely not a recommended approach) with sudo rm -rf /usr/local/lib/python3.8/dist-packages/OpenSSL sudo rm -rf /usr/local/lib/python3.8/dist-packages/pyOpenSSL-22.1.0.dist-info/ and reinstalled using pip3 install pyOpenSSL==22.0.0. The other version was having some issue as described … Read more

How to check if input is float or int?

TLDR: Convert your input using ast.literal_eval first. The return type of input in Python3 is always str. Checking it against type(2.2) (aka float) and type(2) (aka int) thus cannot succeed. >>> number = input() 3 >>> number, type(number) (‘3’, <class ‘str’>) The simplest approach is to explicitly ask Python to convert your input. ast.literal_eval allows … Read more

Python SSL certificate verify error

I have found this over here I found this solution, insert this code at the beginning of your source file: import ssl try: _create_unverified_https_context = ssl._create_unverified_context except AttributeError: # Legacy Python that doesn’t verify HTTPS certificates by default pass else: # Handle target environment that doesn’t support HTTPS verification ssl._create_default_https_context = _create_unverified_https_context

How to click on the anchor element when the spinner obscures it using Selenium and Python?

To click() on the element with text as Driver Schedule as it is an <a> node you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies: Using LINK_TEXT: WebDriverWait(driver, 20).until(EC.invisibility_of_element((By.CSS_SELECTOR, “div.app-spinner-layer.active”))) WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.LINK_TEXT, “Driver Schedule”))).click() Using PARTIAL_LINK_TEXT: WebDriverWait(driver, 20).until(EC.invisibility_of_element_located((By.XPATH, “//div[@class=”app-spinner-layer active”]”))) WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT, “Driver Schedule”))).click() Using CSS_SELECTOR: … Read more

Speed up bitstring/bit operations in Python?

There are a couple of small optimizations for your version. By reversing the roles of True and False, you can change “if flags[i] is False:” to “if flags[i]:“. And the starting value for the second range statement can be i*i instead of i*3. Your original version takes 0.166 seconds on my system. With those changes, … Read more