When running with Python subprocess. There is an error because only the local library is loaded.

Asked 2 years ago, Updated 2 years ago, 79 views

I made an anaconda python 2.7 virtual environment and am interpreting it.

As a subprocess module curl process method a.If you run the py file... I didn't write an anaconda environment library, but I connected it to a local library, so an error occurred. Strangely enough, at the terminal a.If you run it as a py file path, the terminal is set to an anaconda environment, so a.The py file runs well, but the subprocess only connects to the local library. I'm trying to keep developing it in an anaconda environment. Is there a solution?

Run.py

import subprocess

try:
    output = subprocess.Popen ('a.py file path', shell = True)

except subprocess.CalledProcessError as e:
    output = e.output

a.py

import library1
import library2
print('hhh')

Library 1 and Library 2 files are stored in site-packages in an anaconda python 2.7 virtual environment.

There is no library 1 or library 2 in local environment Python 2.7, and we would like to develop it in an anaconda environment.

It's roughly this error.

Traceback (most recent call last):
  File "/home/uk/ProjectEn/backend_test/preprocess_MFCC.py", line 4, in <module>
    import librosa
  File "/usr/local/lib/python2.7/dist-packages/librosa/__init__.py", line 12, in <module>
    from . import core
  File "/usr/local/lib/python2.7/dist-packages/librosa/core/__init__.py", line 109, in <module>
    from .time_frequency import *  # pylint: disable=wildcard-import
  File "/usr/local/lib/python2.7/dist-packages/librosa/core/time_frequency.py", line 10, in <module>
    from ..util.exceptions import ParameterError
  File "/usr/local/lib/python2.7/dist-packages/librosa/util/__init__.py", line 67, in <module>
    from .utils import *  # pylint: disable=wildcard-import
  File "/usr/local/lib/python2.7/dist-packages/librosa/util/utils.py", line 111, in <module>
    def valid_audio(y, mono=True):
  File "/usr/local/lib/python2.7/dist-packages/librosa/cache.py", line 49, in wrapper
    if self.location is not None and self.level >= level:
AttributeError: 'CacheManager' object has no attribute 'location'

The terminal Python is Anaconda.

uk@uk-master:~$ python
Python 2.7.15 |Anaconda, Inc.| (default, Oct 23 2018, 18:31:10) 
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

python subprocess

2022-09-22 11:14

1 Answers

Of course, the virtualenv property is unknown because you are running one more shell.

It is difficult to answer specifically because the operating system is unknown, but if it is unix/liunx, you can do it as follows. I think Windows can run and run the batch file as well.

output = subprocess.Popen('source activate; python a.py', shell=True)


2022-09-22 11:14

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.