I have the following configuration with hydra:
data_files: null
theta: 0.2
use_weights: true
I can override this as:
python -m apps.test_hydra data.data_files=x
However, when I try to specify a list as:
python -m apps.test_hydra data.data_files=[x,y]
Then I get the following error:
zsh: no matches found: data.data_files=[x,y]
I am not sure if this is some issue with the zsh shell or hydra issue
Wrap the string in quotes to avoid [ being interpreted as a glob expression.
python -m apps.test_hydra 'data.data_files=[x,y]'
On a hydra github issue, they use the following syntax. You might have to do something similar.
$ python -m apps.test_hydra 'data#data_files=[x, y]'
Use " \ " before special characters.
python -m apps.test_hydra data.data_files=\[x,y\]
Related
This happens to me almost every day:
pip isntall matplotlib --upgrade
ERROR: unknown command "isntall" - maybe you meant "install"
There is one obvious solution; learn how to type install correctly. So far, that hasn't gone well
I've been wondering, is there a way to instead have pip run the install command when I type isntall? It already recommends the solution, so why not just run it instead of making me type it again.
I'm aware of how silly of a question this is, but I honestly can't seem to type install correctly (I've had to correct it twice already in this question)
You can use thufuck, when you make a typo like this, just write fuck, you can also customize this later, and it will show the probably correct way to do it.
https://github.com/nvbn/thefuck
You can create a function to solve this (stick it in your .bashrc or what-have-you).
pip() {
if [[ $1 == "isntall" ]]; then
command pip install ${#: 2}
else;
command pip $#
fi
}
If I wrote that correctly it will catch your mispeling and run the command properly.
Disclaimer
This is not a solution to be taken seriously, rather of the "you can do this a well" kind. The code uses knowledge of internal pip implementation and may break on new release of pip.
You can patch the related pip logic in a custom sitecustomize module. Create a file sitecustomize.py with the following contents:
import re
import pip._internal.cli.main_parser as pip_cli_parser
from pip._internal.exceptions import CommandError
error_pattern = re.compile(
r'unknown command "(?P<cmd>.*?)"(?: - maybe you meant "(?P<guess>.*?)")?'
)
parse_command_orig = pip_cli_parser.parse_command
def parse_command(args):
try:
return parse_command_orig(args)
except CommandError as err:
msg = str(err)
cmd_name, guess = error_pattern.search(msg).groups()
if guess is not None:
cmd_args = args[:]
cmd_args.remove(cmd_name)
return guess, cmd_args
else:
raise err
pip_cli_parser.parse_command = parse_command
Place the file in the site-packages directory where pip is installed to. You can find it e.g. by running pip -V:
$ pip -V
pip 21.2.3 from /tmp/tst/lib64/python3.10/site-packages/pip (python 3.10)
The target directory in this example is thus /tmp/tst/lib64/python3.10/site-packages.
Now pip's command parser will be patched each time a Python process starts:
$ pip lit # instead of 'list'
Package Version
---------- -------
pip 22.0.4
setuptools 57.4.0
I ended up editing the a file in the pip folder to add an sintall command. In [path_to_python]\Lib\site-packages\pip_internal\commands_init_.py, there is a dictionary that looks like this...
commands_dict: Dict[str, CommandInfo] = {
"install": CommandInfo(
"pip._internal.commands.install",
"InstallCommand",
"Install packages.",...
And I just added a dictionary entry for 'isntall'
"isntall": CommandInfo(
"pip._internal.commands.install",
"InstallCommand",
"Install packages.",
)
Definitely not an ideal solution because any new env of update would require the same edit, but for now it's working well and doesn't require any new typing after the typo. DEfinitely still happy to hear a better answer
I am new to transcrypt. I created a test python file,test.py
def test_def(a: list):
for i in range(len(a)):
print(i)
xx = [2, 3, 4]
test_def(xx)
I have python 3.9. If I run the python file, it runs and prints as expected.
Running transcrypt gives following error
> python -m transcrypt -b -m -n .\test.py
Error while compiling (offending file last):
File 'test', line 2, namely:
Error while compiling (offending file last):
File 'test', line 2, namely:
Aborted
I am not sure what it expects and why is it giving the error, any help would be appreciated.
What version of Transcrypt are you using? Wasn't able to replicate the error using Python 3.9.0 and Transcrypt 3.9.0. You can check like this (Win):
> transcrypt -h | find "Version"
# and may as well double check that the right version of python was used:
> python --version
The Python and Transcrypt versions should match, as Transcrypt uses Python's AST that may change between versions.
Another aspect is that I first installed Transcrypt into a virtual env as follows (Win):
> py -3.9 -m venv wenv
> wenv\Source\activate.bat
> pip install transcrypt
> python -m transcrypt -b -m -n test.py
It sometimes happens that one inadvertently uses the wrong version of Python. 'py' is the Python launcher on Windows and useful to launch the right version if you have multiple versions installed. On Linux there are typically binaries in /usr/bin such as 'python3.9' or a symlink such as 'python3' that links to the most recent 3 version. Installing into a virtual env as demonstrated is also helpful, as various problems can come about otherwise.
The above compiled test.py without error (Win 10 cmd.exe). Fwiw, the file was saved as utf-8 and compile worked with and without a BOM.
I am a beginner trying to learn Python. I wrote a program using Geany and would like to build and execute it but I keep getting this error: "The system cannot find the path specified". I believe I added the right info to the Path though:
Compile C:\Python373\python -m py_compile "%f"
Execute C:\Python373\python "%f"
this doesn't work. Can anyone help me figure it out. Thank you.
You have to be sure about the path of the python. So use this
import sys
print(sys.path)
For Python36 the path is as following:
C:\Users\user\AppData\Local\Programs\Python\Python36
In Python 3
Under 'Python commands', look for the 'Compile' line. Enter the following in the 'Command' box. Make sure you get the spaces right. You should have 'C:\Python34\python' followed by a space, and the rest of the command. If you have 'Python 34', with a space between Python and 34, Geany will not be able to run your code. Also, make sure your capitalization matches what you see here exactly.
C:\Python34\python -m py_compile "%f"
or use the path as the following
C:\Users\user\AppData\Local\Programs\Python\Python36 -m py_compile "%f"
Under 'Execute commands', look for the 'Execute' line. Enter the following in the 'Command' box, paying attention once again to the spaces.
C:\Python34\python "%f"
or
C:\Users\user\AppData\Local\Programs\Python\Python36 "%f"
Test your setup by running hello.py again.
Python 2
If you installed Python 2.7 instead of Python 3, the commands you want are probably:
C:\Python27\python -m py_compile "%f" or path of your python -m py_compile "%f"
and
C:\Python27\python "%f" or path of your python "%f"
See this link for more information:http://introtopython.org/programming_environment_windows.html
#Bryan McCormack,
At the Compile and Execute command field only, type python (of course matching the small letter case as in python.exe) without specifying the full python directory. Like:
Compile: python -m py_compile "%f"
Execute: python "%f"
Then just click OK, and Compile and Execute. Hope it will run the program well. If also, at the time of python installation there is no environment path is set, then set the python directory to the environment variable using command set or manually from the Control Panel > System > Advanced System Setting > Environment Variables > Path
NB: All the Configuration settings of Geany Execute command can be found at the Geany_install_directory\data\filedefs\filetypes.python for python file type at line:
[build_menu]
FT_00_LB=_Compile
FT_00_CM=python -m py_compile "%f"
EX_00_LB=_Execute
EX_00_CM=python "%f"
So, I have Anaconda, OSGeo and Python2.7 installed on my computer.
I'm also using Spyder. In Spyder :
>>> import sys
>>> sys.executable
'C:\\ProgramData\\Anaconda3\\pythonw.exe'
Which is what I want.
However, in the windows command line and powershell :
$ python3
>>> import sys
>>> sys.executable
'C:\\Progra~1\\OSGeo4W\\bin\\python3.exe'
Which is not what I want. I want to use 'C:\\ProgramData\\Anaconda3\\pythonw.exe' (or python.exe, not sure) when using python3 in the command line.
Also :
$ pip3
Fatal error in launcher: Unable to create process using '"'
I don't get why python3 in the windows command line points to OSGeo's version of Python3. Here is my path :
C:\Python27\;C:\Python27\Scripts;C:\ProgramData\Anaconda3;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Git\cmd;C:\Program Files\PuTTY\;C:\Progra~1\OSGeo4W\bin\;C:\Program Files\Microsoft\R Open\R-3.4.0\bin
I also have an environment variable called PYTHONHOME
C:\ProgramData\Anaconda3
Moreover (for completeness of information), I have python 2 installed :
$ python
File "C:\ProgramData\Anaconda3\lib\site.py", line 177
file=sys.stderr)
^
SyntaxError: invalid syntax
($ pip outputs the same thing).
Having python3 and python2.7 both work when using python3 and python (respectively) in the windows command line would be a nice bonus, but it's not really my priority.
There are probably several things you have to take care of:
In general the search order of the Windows PATH is from left to right starting with the system PATH. The first matching element wins. In your case this is correct because the system will search C:\ProgramData\Anaconda3\ first. However in that folder is no executable called python3 by default. On my system I created a simlink pointing to python.exe. On your system you can do it in PowerShell like this:
New-Item -Path C:\ProgramData\Anaconda3\python3.exe -ItemType SymbolicLink -Value C:\ProgramData\Anaconda3\python.exe
pip is located in Scripts\ folder so in your case you have to add C:\ProgramData\Anaconda3\Scripts to your PATH and create the corresponding simlinks again. In this case you have to create two of them because pip.exe is appending its name to the script that is trying to call (i.e. if your exe file is called foo.exe it will try to call foo-script.exe which does not exist) you can create the simlinks in PowerShell with those two commands:
New-Item -Path C:\ProgramData\Anaconda3\Scripts\pip3.exe -ItemType SymbolicLink -Value C:\ProgramData\Anaconda3\Scripts\pip.exe
and
New-Item -Path C:\ProgramData\Anaconda3\Scripts\pip3-script.py -ItemType SymbolicLink -Value C:\ProgramData\Anaconda3\Scripts\pip-script.py
Like this you will be able to use python3 and pip3 from your cmd line. Please check for similar problems with your python2 installation folder.
Hope it helps.
I just installed the git master branch of IPython. The following:
In [1]: run -m my_packages.my_module -verbosity 20
returns an error:
UsageError: option -v not recognized ( allowed: "nidtN:b:pD:l:rs:T:em:G" )
Even though the following works:
$ python -m my_packages.my_module -verbosity 20
I am using argparse as follows:
parser = argparse.ArgumentParser(description='my_program')
parser.add_argument('-verbosity', help='Verbosity', required=True)
Any thoughts why?
Add -- to stop the command-line parsing at a certain point:
In [1]: %run -m my_packages.my_module -- -verbosity 20
This is standard behavior used by argparse for adding extra positional arguments.