I just updated my project to Python 3.7 and I'm seeing this error when I run mypy on the project: error: "Type[datetime]" has no attribute "fromisoformat"
datetime does have a function fromisoformat in Python 3.7, but not in previous versions of Python. Why is mypy reporting this error, and how can I get it to analyze Python 3.7 correctly?
Things I've tried so far:
Deleting .mypy_cache (which has a suspicious looking subfolder titled 3.6)
Reinstalling mypy with pip install --upgrade --force-reinstall mypy
To reproduce:
Create a python 3.6 project
install mypy 0.761 (latest) in the project venv
scan the project with mypy (mypy .)
update the project to python 3.7
add a file with this code in it:
from datetime import datetime
datetime.fromisoformat('2011-11-04 00:05:23.283')
scan the project again (mypy .) [UPDATE: this actually works fine. It was rerunning my precommit hooks without reinstalling pre-commit on the new Python version venv that was causing the problems.]
You are running mypy under an older version of Python. mypy defaults to the version of Python that is used to run it.
You have two options:
You can change the Python language version with the --python-version command-line option:
This flag will make mypy type check your code as if it were run under Python version X.Y. Without this option, mypy will default to using whatever version of Python is running mypy.
I'd put this in the project mypy configuration file; the equivalent of the command-line switch is named python_version; put it in the global [mypy] section:
[mypy]
python_version = 3.7
Install mypy into the virtualenv of your project, so that it uses the exact same Python version.
Note that if you see this issue (and didn't accidentally set --python-version, on the command-line or in a configuration file, you are certainly not running mypy from your project venv.
The solution was simple: simply run mypy with the --python-version flag. so in my case it was --python-version=3.7.
If you use pre-commit, you can also add this as an argument in a precommit check in your .pre-commit-config.yaml. Mine looks like this:
repos:
...
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.750 # Use the sha / tag you want to point at
hooks:
- id: mypy
args: [--python-version=3.7]
If you run mypy often from the command line you can also add it to a config file as described herehttps://mypy.readthedocs.io/en/stable/config_file.html.
Another note: if mypy is reporting errors when your pre-commit hooks run, but not when it is run by itself from the project venv, then you need to either
add python-version as an argument like I do above, or
reinstall pre-commit in the new project venv (with the correct python version)
Related
Versions:
Python: 3.10.4
Pylint: 2.15.3
Visual Studio Code: 1.72.2
The .pylintrc file was generated using
pylint --generate-rcfile
command.
It has the following option configured:
[METHOD_ARGS]
# List of qualified names (i.e., library.method) which require a timeout
# parameter e.g. 'requests.api.get,requests.api.post'
timeout-methods=requests.api.delete,requests.api.get,requests.api.head,requests.api.options,requests.api.patch,requests.api.post,requests.api.put,requests.api.request
However I see an error which sounds:
Unrecognized option found: timeout-methods Pylint(E0015:unrecognized-option)
The documentation states that option timeout-methods is supported: https://pylint.pycqa.org/en/latest/user_guide/configuration/all-options.html#timeout-methods.
So I am lost why do I have that error displayed by pylint in visual studio code.
As the comments under the original code showed, the pylint version bundled in the VS Code extension and the one that was used to generate the .pylintrc file differ.
Normally, the VS Code Pylint extension should use the pylint version installed in the Python environment that you configured to use for your project, and only falls back to the bundled version if no other pylint version was found. See also the extension docs for details.
Check the following:
Make sure that you configured the correct Python environment for your project. See Select a Python interpreter in the docs.
Make sure that you have installed pylint in the Python environment you have configured for your project, and are not accidentally using a pylint installation from your global Python environment. After configuring the Python interpreter (see step 1), once you open a new terminal in VS Code this environment should be activated by default. Run pip list | grep pylint (macOS/Linux) or pip list | findstr pylint (Windows) to check if pylint is installed.
If both 1 & 2 are fulfilled and you still have problems, check if pylint.importStrategy is maybe set to useBundled in your VS Code settings.json, and remove it or set it to fromEnvironment.
pylint 2.15 take this option into account correctly. But it was released only 2 month ago. Your error must come from the pylint version included in visual studio code that might lag a little behind and do not handle it yet.
I am trying to create python based 'Function Apps' in Azure, but struggling with the very first step on importing azure.functions. Even the default code that is created (when a new Function App is created using Azure Portal) will have this line of code: import azure.functions as func
When I copy the code to Pycharm i get errors depending on whether i choose Conda or direct python.exe interpreter. When i do NOT use Conda i get below msg:
Starting with v5.0.0, the 'azure' meta-package is deprecated and
cannot be installed anymore. Please install the service specific
packages prefixed by azure needed for your application. .... A
more comprehensive discussion of the rationale for this decision can
be found in the following issue:
https://github.com/Azure/azure-sdk-for-python/issues/10646
If i use Conda env i get below msg:
UnsatisfiableError: The following specifications were found
to be incompatible with the existing python installation in your environment:
Specifications:
azure -> python[version='>=2.7,<2.8.0a0|>=3.5,<3.6.0a0|>=3.6,<3.7.0a0']
Your python: python=3.7
If python is on the left-most side of the chain, that's the version
you've asked for. When python appears to the right, that indicates
that the thing on the left is somehow not available for the python
version you are constrained to. Note that conda will not change your
python version to a different minor version unless you explicitly
specify that.
Given that azure.functions is the core module i am sure there is something else at wrong here, but not able to figure out.
Some of the responses for similar issues indicated to install it via pip command (pip install azure==4.0.0). I am able to run this cmd successfully on my windows10 laptop, but Pycharm still says no module found.
Any guidance is appreciated.
For the no module found error, please ensure that the modules are installed at the PyCharm end. You would need the Azure-Functions module.
File> Settings> Project :YOUR_PROJECT_NAME > Project Interpreter
If you did not find the azure-functions module.
Click on the '+' icon that is visible in the same window.
Add Azure-Functions module in the subsequent Available Packages Window like below. Click on the Install Package
Close the windows and try importing azure.functions
import azure.functions
Alternatively you can install the Azure Functions through the pip command :
https://pypi.org/project/azure-functions/
pip install azure-functions
Additional Information :
https://pypi.org/project/azure/4.0.0/
Reading through the documentation, it appears like the azure functions is not included in the Azure Module. They include only the below.
azure-mgmt v4.x
azure-applicationinsights v0.1.x
azure-batch v4.x
azure-cosmosb-table v1.x
azure-datalake-store v0.0.x
azure-eventgrid v1.x
azure-graphrbac v0.40.x
azure-keyvault v1.x
azure-loganalytics v0.1.x
azure-servicebus v0.21.x
azure-servicefabric v6.3.0.0
azure-servicemanagement-legacy v0.20.x
azure-storage-blob v1.x
azure-storage-queue v1.x
azure-storage-file v1.x
Update for Conda interpreter:
When I used the Conda interpreter.
File> Settings> Project :YOUR_PROJECT_NAME > Project Interpreter
I unselected/Unclicked the "Use Conda Package Manager" (green circle - Conda Icon) which is on the right Project Interpreter Window - Click on it to unselect it. When you unselect it, there will be no highlight behind the icon.
Now I clicked on the add('+' icon) button and searched for the azure-functions, installed the same - Above mentioned steps.
I have a Windows machine so I' trying to have Travis CI run my python scripts directly from github. Is it possible to run Travis CI python scripts directly from my github and not from my local repository?
You can integrate TracisCI to your GItHub repo
That way, on each push, your associated TravisCI job will run and execute what you have specified.
Regarding your travis.yaml, it has to respect the yaml syntax format:
language: python
sudo: enabled
python:
-"3.5" <========= incorrect: must be - "3.5"
See Building a Python Project: you will see a space between - and "x.y" version.
Regarding the unittest error, see "unittest installation error Could not find a version that satisfies the requirement"
unittest is a standard module, which you don't need to install.
I've installed PyCharm with the robotframework support plugin.
The .robot files are identified successfully and I was able to create a simple script and run it in pyCharm.
However, my problem is that no keywords nor even the robotframework libraries (selenium2library) are recognized by pycharm in order to be autocompleted when typing them.
I also have the intellibot plugin installed.
Is there something that I'm missing? Is there another configuration file somewhere?
Thanks,
Try to set up your Library to robotframework-selenium2library == 1.8.0, then the issue will disappear.
If you have the last version it doesn't work for me.
My solution:
Uninstall the 'Robot framework support' (PyCharm/File/Settings/Plugins)
Uninstall 'Intellibot' (PyCharm/File/Settings/Plugins) (Uninstall all similar plugins!)
Exit PyCharm
Uninstall robotframework-seleniumlibrary (Open command prompt with administration mode: pip uninstall robotframework-seleniumlibrary)
Install robotframework-seleniumlibrary 3.3.1 (Command prompt: pip install robotframework-seleniumlibrary==3.3.1)
Open PyCharm
Install 'IntelliBot #SeleniumLibrary Patched' (PyCharm/File/Settings/Plugins)
(If it isn't working then try the following: PyCharm/File/Invalidate Caches/Restart... and click the 'Invalidate and Restart')
There is a bug in the intellibot plugin.
To resolve you need to
1. Uninstall your current intellibot plugin
2. Search for "IntelliBot #SeleniumLibrary Patched" in the plugins repository.
3. Install this patched plugin.
This worked for me.
You can try install "Robot Framework support" plugin.
it working for me.
use plugin Intellbot#SeleniumLibrary Patched
and robotframework-seleniumlibrary version 3.3.1
It works for me after lot of research from the internet
I recomend to use lte2000 fork: https://github.com/lte2000/intellibot
It works fine for me (Pycharm 2020.1, Robot Framework 3.2.2 and SeleniumLibrary 4.5.0)
In our main_resources.robot we need to give file path as below for the library files which contain definition of function
Library ../lib/SampleRest/SampleRest.py
When you do cntl+click on above SampleRest.py it should be navigated to that file
Your SampleRest.py should contain all your function definitions as below
try:
from .api import *
except:
from api import *
class SampleRest(
events,
repository,
devices
):
"""
This library will provides keywords to automating the cloud test cases
"""
ROBOT_LIBRARY_SCOPE = 'GLOBAL'
ROBOT_LIBRARY_VERSION = 1.0
def __init__(self):
for base in SampleRest.__bases__:
base.__init__(self)
Once I declare this I can use any of functions present in above devices.py file from robot file and it will be successfully navigated
Also please check your robotframework-seleniumlibrary version it should be 3.3.1 because for latest version navigation is an issue
I have been troubled by this for what seems to be forever.
Here are my configuration steps, and so far everything is working like a charm.
My setup:
Installed Python 3.9.x => added path to variables in "windows environment Variables" Check python and pip versions.
install selenium
install robotframework
install robotframework-seleniumlibrary
Install Pycharm and set Interpreter to Python 3.9.x
Install Plugin: "IntelliBot #SeleniumLibrary Patched" - Do not install Selenium2Library This is what causes the IDE issues.
Restart IDE and enjoy. And for those just getting into Robotframework, dont forget to add webdrivers.
For this I made a folder in root (called it webdrivers) and also added this to my Windows Enviro variables. This allows me to call them from any project folder.
I am going through the same problems... I've tried IntelliBot, IntelliBot #patched, Robot Framework Support plugins.
Now I am testing the Hyper RobotFramework Support plugin [link] and for now, looks the best from all of these.
With it I have some auto-complete support, also ctrl+click (navigation) works nice (better than in IntelliBot). Not perfect, but the best it has been so far.
I have installed:
PyCharm 2021.3.2
Python 3.10.2
Robot Framework 4.1.3
selenium 4.1.3
robotframework-seleniumlibrary 6.0.0
(on windows you can run the command pip list to see the version of the libraries that have been installed using pip)
This question already has answers here:
Dealing with multiple Python versions and PIP?
(28 answers)
Closed 5 years ago.
I've installed django using the pip command (pip install Django), but i can't run it using the py command, as it can't find the module.
I can only make it works using 'python' command.
Here is a summary of the screenshot I have atttached
$ python --version
Python 3.6.1
$ py --version
Python 3.6.0
It also looks like django works only with 3.6.1.
Is there any way to set both commands to run newest version of python?
Screenshot:
You're using Python launcher for Windows when you executepy. You could be specific about which Python interpreter version that you want py to execute with this command:
> py -3.6
See this section from PEP 397:
Python Version Qualifiers
If no version qualifiers are found in a command, the environment
variable PY_PYTHON can be set to specify the default version qualifier
- the default value is "2". Note this value could specify just a major version (e.g. "2") or a major.minor qualifier (e.g. "2.6"), or even
major.minor-32.
If no minor version qualifiers are found, the environment variable
PY_PYTHON{major} (where {major} is the current major version qualifier
as determined above) can be set to specify the full version. If no
such option is found, the launcher will enumerate the installed Python
versions and use the latest minor release found for the major version,
which is likely, although not guaranteed, to be the most recently
installed version in that family.
In addition to environment variables, the same settings can be
configured in the .INI file used by the launcher. The section in the
INI file is called [defaults] and the key name will be the same as the
environment variables without the leading PY_ prefix (and note that
the key names in the INI file are case insensitive.) The contents of
an environment variable will override things specified in the INI
file.
Plus Python launcher isn't just limited to launching different Python versions, it also parses shebang #! in source code files, providing a functionality similar to that in *nix operating systems in Windows.
*Refer to Python Launcher for Windows documentation.
On windows, py is an executable stored in the C:\Windows folder. I honestly don't know what it contains, as I am used to where it is a symbolic link on linux, and my windows install shows the normal python executable as being a fraction of the size of py, despite my being quite sure that they point to the same installation. Regardless, you can fix your problem by deleting or renaming (python.bak, etc) the executable you don't want to keep using from the Windows folder, then copying the one you want in place and renaming it to the same name that you previously deleted or renamed. I can't imagine this is the official way to fix this problem, but this will work. Also, in the future, feel free to specify the version you are installing to with pip explicitly if you want to be sure of which installation you are using instead of just running whatever points to pip:
py -m pip install packagename
python -m pip install packagename
Running into problems with multiple python versions on the same system is quite common with Windows, so setting up a virtual environment may be beneficial. This is explained in the Django Windows install how-to.