to describe the scenario, a function on the company’s Jboss server needs to call a python script on a centos7.3 machine with salt mode. Python version is 3.7, and the script will call back an HTTP interface to feedback the execution result. In the test environment, I had Linux machine root privileges, installed Python and dependent modules, and tested that the local execution of the PY script was normal and the JBoss Salt calls were normal. After publishing production, it was found that there were no callbacks after the call was issued, and the problem was located.
production environment configuration, the python script has been manually executed, confirm that the script can execute properly. First confirm that the command was actually sent to the Linux server. Listen to the /var/log/messages log and see the failed salt call:
there is an error reason: salt-minion: ModuleNotFoundError: No module named ‘openpyxl’, which is very strange. It is executed directly on the machine, and all the dependencies are there. Why does salt call fail?Therefore, I started to search various baidu sites, and found that there were a lot of materials in this field but not many directly related ones. Either it was a method to solve the installation of Python modules, or the salt-related package missing problem occurred when salt stack called Python, which could not solve my problem.
after communication with colleagues, colleagues suspected that it was caused by different paths of PIP installation modules for different users on the Linux machine. I had no root rights in the production environment, which was the most significant difference from the test environment. Based on this idea, I first inquired the path of the module installed in pip3:
modules were stored in the private path of the current user. Meanwhile, when I wanted sudo to execute the pip3 installation, I found that the system prompt command did not exist and the same error message appeared when I executed the python script as in the messages log:
$ sudo -H python3 static_analyzer.py
File "static_analyzer.py", line 7, i <module>
import openpyxl
ModuleNotFoundError: no module named 'openpyxl'
$ sudo -H pip3 install openpyxl -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com --user
sudo:pip3: command not found
is a good idea, so I looked for ways to share the PIP installation module by user, or at least make it Shared by root. According to the command that this does not exist, one of the blog posts suggests a simple solution, which is to hang the soft connection directly so that root users can find python3 and pip3:
#如下软连接是为了使命令在root用户下 也能正常使用
sudo ln -snf /usr/local/python3/bin/python3 /usr/bin/python3
sudo ln -snf /usr/local/python3/bin/pip3 /usr/bin/pip3
Sure enough, after a soft connection, sudo mode can use python3 and pip3 normally:
sudo -H pip3 install openpyxl -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com --user
With this in mind, let’s run the python script in sudo mode to verify that the current environment root user can execute properly:
sudo -H python3 python_script.py
is completely normal. Without the above soft connection, a ModuleNotFoundError in the Messages log would have appeared in the same command, and so far we have solved the problem that the root user of the PIP3 installed module cannot find.
at the end of the last, through the jboss production environment service page to submit the request, the whole process smoothly completed, perfect!
p>
reference:
view the path to installing a python module using PIP install under Linux
solve pip3 command to install the installation package in the home. Local/lib/python3.5/dist – the problem of packages directory p>
python3: command not found
sudo used with python
Read More:
- IOS solves the problem of this action could not be completed. Try again
- Centos7 solves the problem of unable to use tab to complete automatically
- Centos8 solves the problem of “failed to set locale, defaulting to c.utf-8”
- Windows subsystem Ubuntu 18.04 solves SSH problem
- Git solves the problem of failed: http request failed
- Git solves pull origin error: the following untracked working tree files would be rewritten by merge
- Android solves the gliding problem of EditText
- Flutter solves the problem of incorrect use of parent datawidget and boundary constraint
- Modulenotfounderror: no module named ‘CV2’ – (version problem)
- Unity Android solves the problem of information flow advertisement closing and error reporting
- Jsonformat annotation solves the problem of time format in the front end of localdatetime
- Vs code solves the problem that latex does not display references and [?] is displayed in the text
- Xcode 5 solves the operation could’t be completed
- Centos8 solves SSH secure shell error algorithmic negotiation failures
- Cannot find module ‘.. / lib / utils / unsupported. JS’ problem in installing node in centos7
- Solve the problem that TeamViewer software prompts that the trial period has expired and cannot be operated remotely
- (Copy python package, the problem generated) pip Fatal error in launcher: Unable to create process using
- Configuration (9) to solve the problem of “setup tools PIP wheel failed with error code 1”, create virtual environments with Python of anaconda
- The background object of thymeleaf is null, which solves the problem of error when the object is empty to get the property value
- UE4 solves lighting need to be rebuilt