Error : 'str' object has no attribute 'system' [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 3 years ago.
Improve this question
It looks like os.system() error.I dont know what to do next.
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import re, platform, os
def init():
cmd = {
'centos': 'yum -y install python-devel && pip install psutil > /dev/null',
'ubuntu': 'apt-get -y install python-dev && pip install psutil > /dev/null'
}
os = platform.platform().lower()
osname = ''.join(key for key in cmd if re.findall(key,os))
try:
import psutil
except ImportError:
try:
os.system(cmd[osname])
import psutil
except Exception as error:
print("Error : {}".format(error))
def collect():
cpu = psutil.cpu_count(logical=False)
print('cpucount: {}'.format(cpu))
if __name__ == '__main__':
init()
os.system() function not accept string???? os.system('apt-get -y install python-dev && pip install psutil > /dev/null') ,It running when in python shell.I dont know how wrong.
[root#master python]# python test.py
Error : 'str' object has no attribute 'system'

os = platform.platform().lower() is your culprit. Use a different name for that local variable.

Related

ModuleNotFoundError: No module named 'tensorflow_io' pip install don't work [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 12 months ago.
Improve this question
Hi I try to train my model, but when I run this command to do it:
$ python3 Tensorflow/models/research/object_detection/model_main_tf2.py --model_dir=models/my_ssd_resnet50_v1_fpn --pipeline_config_path=models/my_ssd_resnet50_v1_fpn/pipeline.config
I get error like so:
ModuleNotFoundError: No module named 'tensorflow_io'
I try to install it with 'pip' but I get another one
$ pip install tensorflow.io
ERROR: Could not find a version that satisfies the requirement tensorflow.io (from versions: none)
ERROR: No matching distribution found for tensorflow.io
I also try to fix it with GitHub issue https://github.com/tensorflow/io/issues/1298 and it work for me. I follow the last comment there and I get
Successfully installed tensorflow-io-gcs-filesystem-0.21.0
and I try it in python3 in terminal:
>>> import tensorflow.io
>>>
So why when I try to train my model it fails ?
Im using MacBook Pro with M1, and I have no idea how to fix it.
Thanks for any help
Use pip install tensorflow_io instead of pip install tensorflow.io

No matching distribution found for sqlite3 [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 1 year ago.
Improve this question
Guys every time I try to install sqlite3 with pip I get the error:
ERROR: Could not find a version that satisfies the requirement sqlite3 (from versions:none)
ERROR: No matching distribution found for sqlite3
My python version: 3.10.0
My pip version: 21.3
How can I solve this? I believe it's regarding my version of python so how can i update the pip to fix this? I've already tried this pip --upgrade pip
Edited:
Guys I installed python 3.7.0 and it's still the same thing.
sqlite3 is part of the standard library, meaning it is already installed with Python.
You can write a script following the documentation, and notice it says nothing about installation procedures.
The error is self-explanatory. For anything that can be installed with pip, you should refer to the source - PyPi. Search for sqlite3 and notice that you get no exact match
Many languages have built-in modules, for example, you seem to have maybe some NodeJS experience, so you can import things like os, readline, net, http modules without needing to npm install. You simply require them.
Python/Pip is no different with a simple import.
this error I mentioned in the question doesn't show up on Linux when I try to install the same things
Is that so? Seems to work for me (Using Docker because I'm on a Mac)
$ docker run --rm -ti --entrypoint=ash python:3.10-alpine
Unable to find image 'python:3.10-alpine' locally
3.10-alpine: Pulling from library/python
Digest: sha256:78604a29496b7a1bd5ea5c985d69a0928db7ea32fcfbf71bbde3e317fdd9ac5e
Status: Downloaded newer image for python:3.10-alpine
/ # pip install sqlite3
ERROR: Could not find a version that satisfies the requirement sqlite3 (from versions: none)
ERROR: No matching distribution found for sqlite3

Error printing variables while debugging Cython

I'm trying to debug some Cython code with gdb that is wrapping C++ code to be called from Python. I followed the instructions in the documentation but I'm getting some errors while debugging that are unrelated to my code. Example:
(gdb) cy print some_variable
Python Exception <type 'exceptions.AttributeError'> 'PyDictObjectPtr' object has no attribute 'items':
Error occurred in Python: 'PyDictObjectPtr' object has no attribute 'items'
I'm also getting this one sometimes (usually after the first one):
Python Exception <class 'gdb.error'> There is no member named ob_sval.:
Error occurred in Python command: There is no member named ob_sval.
To debug the code I created an environment with Docker:
FROM debian
RUN apt-get update && apt-get upgrade -y && apt-get install -y \
build-essential gdb-python2 python-dbg python-dev \
python-pip python-numpy-dbg
RUN pip install cython pygments
CMD bash
I found two related posts in the cython-users google group but with no answer.
An issue was finally opened in Cython (thanks #hygorxaraujo!) and it was identified as a defect:
https://github.com/cython/cython/issues/2699
Pull requests welcome!

Python newbie: pip install and syntax problems [duplicate]

This question already has answers here:
Why does "pip install" inside Python raise a SyntaxError?
(7 answers)
Closed 6 years ago.
New to Python here. I am running Python 2.7.7 x86 and Windows 7. I am trying to install the requests module. I've tried:
pip install requests
in the Python shell and in the Windows command line (cmd) (I saw this question, which suggested using cmd), and I keep getting the same error:
SyntaxError: invalid syntax
I tried to check if pip even installed correctly by running:
installed_packages = pip.get_installed_distributions()
installed_packages_list = sorted(["%s==%s" % (i.key, i.version) for i in installed_packages])
print installed_packages_list
Which I got from this question. I got [] as the output. I'm interpreting this to mean that pip wasn't successfully installed. I tried reinstalling pip by running get-pip.py, and got the output:
Requirement already up-to-date: pip in c:\python27\lib\site-packages
Cleaning up...
Which I'm interpreting as Python telling me pip was installed. I'm really confused now... how do I make sure pip is correctly installed, and then install the requests module? Any help would be appreciated.
This is a commonly asked question, and one for which there's hardly a canonical answer that would be on-topic for SO (honestly this is more a Superuser thing, but since it's pertinent to coding -- even though it's NOT coding by any means -- it will fly here).
If you have pip (by running get-pip.py or etc) it will exist in your Python directory. If you're running Python 2.7, let's assume that that directory lives at C:\Python27\. In which case, pip exists at C:\Python27\scripts\pip.exe.
You can add that to your %PATH%, or navigate there each time you want to use pip. Whatever is most convenient. If nothing else:
COMMAND PROMPT WINDOW:
C:\users\yourname>set PATH = %PATH%;C:\python27\scripts
C:\users\yourname>pip install requests

Yum not working? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I have default python 2.7 and i try to install python3.3 and install pip3 and Django.now when i try to install others using yum i got this error.for a example yum update
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:
No module named yum
Please install a package which provides this module, or
verify that the module is installed correctly.
It's possible that the above module doesn't match the
current version of Python, which is:
2.7.5 (default, Nov 12 2013, 16:18:42)
[GCC 4.8.2 20131017 (Red Hat 4.8.2-1)]
If you cannot solve this problem yourself, please go to
the yum faq at:
http://yum.baseurl.org/wiki/Faq
How can i fix this error?
There is probably many python versions on your system and only one of them has the yum library installed. For some reason the python binary called when you run yum on the command line is not the one who has the yum library installed.
Find the list of python 2 binaries available on your system. Run as root:
find / -type f -executable -name 'python2*'
The output will probably look like that:
/usr/bin/python2.6
/usr/bin/python2.7
...
etc...
For each one of these, run
/usr/bin/python2.x
You'll get a python prompt.
Run:
>>> import yum
Do this for every python binary until you find one that doesn't raise an ImportError at this step.
Then find out what is the path that yum is using to run python.
This is the first line in the yum script. Run
cat `which yum` | head -1
You'll probably get:
#!/usr/bin/python
Now, run as root:
ln -s /usr/bin/python2.x /usr/bin/python
(replace python2.x with the good python version you found earlier).
I have the same problem.
Yum has been written in Python lang.
So when you upgrade your default Python to new version it will make problem for yum.
If you get python --version it will tell you 3.3.
For solving this problem , change python command to python2.7.
First check it:
user#host:~$ ls -l /usr/bin/python
lrwxrwxrwx 1 root root 9 Sep 28 2013 /usr/bin/python -> python3.3
Try it:
mv /usr/bin/python /usr/bin/python-origin
ln -s python2.7 /usr/bin/python
Then check it:
user#host:~$ ls -l /usr/bin/python
lrwxrwxrwx 1 root root 9 Sep 28 2013 /usr/bin/python -> python2.7
If you wish to install python3 in CentOS you should install that via source code.
download main source code via python.org website.
extract archive file.
./configure
make
make install

Categories