subprocess.CalledProcessError: Command 'unset VIRTUAL_ENV; poetry run python3 manage.py makemigrations --dry-run' returned non-zero exit status 127 [closed] - python

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed yesterday.
Improve this question
I install pre-commit.
I have a function in my models.py for return a default image:
def get_lab_logo_url():
return static("menu/images/lab_logo.png")
This function is used in models:
class Category(Timestampable, Authorable, Publishable, Permalinkable, Sortable, models.Model):
name = models.CharField(max_length=64, verbose_name=_("نام دسته‌بندی"))
subtitle = models.CharField(max_length=64, null=True, blank=True, verbose_name=_("نام فرعی دسته‌بندی"))
image = models.ImageField(upload_to="categories/", blank=False, null=False, default=get_lab_logo_url, verbose_name=_("تصویر دسته‌بندی"))
objects = CategoryManager()
Now I want to change this file to svg file:
def get_lab_logo_url():
return static("menu/images/lab_logo.svg")
when I want commit this change:
git add .
git commit -m "change logo file"
I got this error:
subprocess.CalledProcessError: Command 'unset VIRTUAL_ENV; poetry run python3 manage.py makemigrations --dry-run' returned non-zero exit status 127.
Thanks for your responses.

Related

Why aren't I able to perform simple arithmetic operations in python using Vscode but I can elsewhere [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 months ago.
Improve this question
essentially when I run something as simple as '3 * 3' in any other IDE I have no issues, however, all arithmetic operations in my Vscode seem to return nothing, the terminal just repeats my PWD essentially.
Note that I am new and learning python but everything else thus far has worked fine, print statements print to the terminal etc but maths docent seem to work.
enter code here: def example(val1, val2):
return val1 * val2
example(2, 6)
Edit: by terminal I mean I am writing the script and clicking the run button in vscode which outputs to said terminal, I have uploaded a SC of what I mean :screenshot of the IDE and terminal output
In some environments, such as the Python REPL (the P stands for "print") and Jupyter Notebook), results are printed out automatically. However, when you run a script from the command line or VS Code, printing isn't automatic. To output something in this case, you need to add a print() command:
def example(val1, val2):
return val1 * val2
result = example(2, 6)
print(result)
Your terminal is running a shell, probably bash not python.
Then, if you want to evaluate that in bash do
$(( 3 * 3 ))

How to execute a batch file? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 1 year ago.
Improve this question
FOR /F "usebackq" %%i IN (`hostname`) DO SET MYVAR=%%i
SET subkey1=%random%%random%%random%%random%%random%%random%
SET subkey1=%subkey1:0=a%
SET subkey1=%subkey1:1=b%
SET subkey1=%subkey1:2=c%
wmic computersystem where caption="%MYVAR%" rename %subkey1%
This is block of code run in Windows BATCH file, I'd like to adapt it for Python app but I can't think of a way to do so.
I've used:
os.system('cmd xxxx')
to run single line of code, but I don't think this will solve my issue with big block of code that can't be run separately.
below is a way to do it (creating the script on the fly)
import os
script = '''FOR /F "usebackq" %%i IN (`hostname`) DO SET MYVAR=%%i
SET subkey1=%random%%random%%random%%random%%random%%random%
SET subkey1=%subkey1:0=a%
SET subkey1=%subkey1:1=b%
SET subkey1=%subkey1:2=c%
wmic computersystem where caption="%MYVAR%" rename %subkey1%'''
with open('script.cmd', 'w') as f:
f.write(script)
os.system('script.cmd')

pytest: getting AttributeError: 'CaptureFixture' object has no attribute 'readouterror' capturing stdout [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 11 months ago.
Improve this question
This should be a simple thing but I can't figure out what is causing the error.
I'm following the pytest docs on how to capture stdout into an object but am getting the following error:
capsys = <_pytest.capture.CaptureFixture object at 0x7f02a1e2f7f0>
def test_can_output_to_stdout(capsys):
print("hello")
> capture = capsys.readouterror()
E AttributeError: 'CaptureFixture' object has no attribute 'readouterror'
test_aaa.py:5: AttributeError
The code I'm using is similar to:
import pytest
def test_can_output_to_stdout(capsys):
print("hello")
capture = capsys.readouterror()
assert "hello" in capture.out
I'm calling the test like so:
py.test --capture=sys --capture=fd test_aaa.py
The versions are:
pytest:
py.test --version
This is pytest version 4.6.5, imported from /usr/local/lib/python3.4/site-packages/pytest.p
Python:
python --version
Python 3.4.8
Any help would be greatly appreciated.
It turns out copy pasting is probably better than writing out the examples. The error was with the attribute name.
It should be capsys.readouterr(), not capsys.readouterror(), and in full:
import pytest
def test_can_output_to_stdout(capsys):
print("hello")
capture = capsys.readouterr()
assert "hello" in capture.out

Script running on Linux gives NameError [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
So I have a python script running on a Linux server. The code:
#!/bin/python
databaseRun = input("Do you want to run all databases: ")
if databaseRun == "yes":
print("yes")
else:
print("no")
This returns and error:
Traceback (most recent call last):
File "./db_upg.py", line 3, in <module> databaseRun = input("Do you want to run all databases: ")
File "string", line 1, in <module> NameError: name 'yes' is not defined
Now if I type this code into PyCharm it runs with no problem. What am I missing? Basically you will put yes or no will be the only to answers
You're probably running this with Python 2 instead of Python 3. Try running it with python3 <scriptname> instead of python <scriptname>. And change the shebang line from #!/bin/python to #!/usr/bin/python3 respectively.
In Python 2, input() reads the input as a code instead of a string. Thus when you type yes, it reads it as a variable yes which is undefined. If you want to run this with Python 2 instead of Python 3 as your tag suggests, use raw_input() instead of input(). Python 2's raw_input() returns a string, similar to Python 3's input().

NameError: name 'ftplip' is not defined [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Following is my python code to make a FTP connection
upload_ftp.py
import ftplib
ftp = ftplip.FTP()
ftp.connect('ip', 21)
print ftp.getwelcome()
try:
print "Logging in..."
ftp.login("username", "password")
except:
"failed to login"
but when i run the code ,i get the following error: NameError:name 'ftplib' is not defined
my#my-pc:/var/www$ python upload_ftp.py
Traceback (most recent call last):
File "upload_ftp.py", line 8, in <module>
ftp1 = ftplip.FTP()
NameError: name 'ftplip' is not defined
Any help would be appreciated..
You have a spelling error in your variable name. So Python thinks you are using an undefined variable.
You have a typo: you writing ftplip.FTP() but it is ftplib.FTP() (lip with p vs lib with b).
Use :
from ftplib import FTP
ftp = FTP()
Return a new instance of the FTP class.

Categories

Resources