首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python包全局安装,但在虚拟环境中失败。

Python包全局安装,但在虚拟环境中失败。
EN

Stack Overflow用户
提问于 2021-12-20 20:06:59
回答 9查看 876关注 0票数 4

我对Python很陌生,并且很难理解安装软件包的不同方法。我在MacOS Catalina。

我尝试在终端中安装package (https://github.com/burtonrj/CytoPy):

代码语言:javascript
复制
pip install cytopy

这个安装得很好。我创建了一个文件test.py:

代码语言:javascript
复制
from cytopy.data.setup import global_init
print("test")

运行良好,即正确导入细胞周期包。

然后,我将在Visual教程中使用Python开始学习以下内容:https://code.visualstudio.com/docs/python/python-tutorial

它说,重要的是要避免将软件包安装到全局解释器环境中,而应使用特定于项目的虚拟环境。我按照Visual代码中的终端教程创建一个虚拟环境:

代码语言:javascript
复制
python3 -m venv .venv
source .venv/bin/activate

现在,我尝试在虚拟环境中安装这个包:

代码语言:javascript
复制
pip install cytopy

最后我犯了很多错误:

主要错误是:

代码语言:javascript
复制
 ERROR: Failed building wheel for fdasrsf
 Successfully built hdbscan
 Failed to build fdasrsf
 ERROR: Could not build wheels for fdasrsf, which is required to install 
 pyproject.toml-based projects

为什么它要通过Visual代码中的终端进行全局安装,而不是在虚拟环境中安装?

编辑我按建议使用了pip3。我还是会犯同样的错误。下面是有关错误的更多日志:

代码语言:javascript
复制
                                          _Nonnull
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:83:53: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
int     pthread_sigmask(int, const sigset_t *, sigset_t *) __DARWIN_ALIAS(pthread_sigmask);
                                                        ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:83:53: note: insert '_Nullable' if the pointer may be null
int     pthread_sigmask(int, const sigset_t *, sigset_t *) __DARWIN_ALIAS(pthread_sigmask);
                                                        ^
                                                         _Nullable
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:83:53: note: insert '_Nonnull' if the pointer should never be null
int     pthread_sigmask(int, const sigset_t *, sigset_t *) __DARWIN_ALIAS(pthread_sigmask);
                                                        ^
                                                         _Nonnull
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:84:43: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
int     sigaction(int, const struct sigaction * __restrict,
                                              ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:84:43: note: insert '_Nullable' if the pointer may be null
int     sigaction(int, const struct sigaction * __restrict,
                                              ^
                                                _Nullable
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:84:43: note: insert '_Nonnull' if the pointer should never be null
int     sigaction(int, const struct sigaction * __restrict,
                                              ^
                                                _Nonnull
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:85:23: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
            struct sigaction * __restrict);
                             ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:85:23: note: insert '_Nullable' if the pointer may be null
            struct sigaction * __restrict);
                             ^
                               _Nullable
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:85:23: note: insert '_Nonnull' if the pointer should never be null
            struct sigaction * __restrict);
                             ^
                               _Nonnull
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:86:24: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
int     sigaddset(sigset_t *, int);
                           ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:86:24: note: insert '_Nullable' if the pointer may be null
int     sigaddset(sigset_t *, int);
                           ^
                            _Nullable
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:86:24: note: insert '_Nonnull' if the pointer should never be null
int     sigaddset(sigset_t *, int);
                           ^
                            _Nonnull
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:87:31: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
int     sigaltstack(const stack_t * __restrict, stack_t * __restrict)  __DARWIN_ALIAS(sigaltstack) __WATCHOS_PROHIBITED __TVOS_PROHIBITED;
                                  ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:87:31: note: insert '_Nullable' if the pointer may be null
int     sigaltstack(const stack_t * __restrict, stack_t * __restrict)  __DARWIN_ALIAS(sigaltstack) __WATCHOS_PROHIBITED __TVOS_PROHIBITED;
                                  ^
                                    _Nullable
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:87:31: note: insert '_Nonnull' if the pointer should never be null
int     sigaltstack(const stack_t * __restrict, stack_t * __restrict)  __DARWIN_ALIAS(sigaltstack) __WATCHOS_PROHIBITED __TVOS_PROHIBITED;
                                  ^
                                    _Nonnull
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:87:53: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
int     sigaltstack(const stack_t * __restrict, stack_t * __restrict)  __DARWIN_ALIAS(sigaltstack) __WATCHOS_PROHIBITED __TVOS_PROHIBITED;
                                                        ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:87:53: note: insert '_Nullable' if the pointer may be null
int     sigaltstack(const stack_t * __restrict, stack_t * __restrict)  __DARWIN_ALIAS(sigaltstack) __WATCHOS_PROHIBITED __TVOS_PROHIBITED;
                                                        ^
                                                          _Nullable
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:87:53: note: insert '_Nonnull' if the pointer should never be null
int     sigaltstack(const stack_t * __restrict, stack_t * __restrict)  __DARWIN_ALIAS(sigaltstack) __WATCHOS_PROHIBITED __TVOS_PROHIBITED;
                                                        ^
                                                          _Nonnull
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:88:24: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
int     sigdelset(sigset_t *, int);
                           ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:88:24: note: insert '_Nullable' if the pointer may be null
int     sigdelset(sigset_t *, int);
                           ^
                            _Nullable
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:88:24: note: insert '_Nonnull' if the pointer should never be null
int     sigdelset(sigset_t *, int);
                           ^
                            _Nonnull
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:89:26: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
int     sigemptyset(sigset_t *);
                             ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:89:26: note: insert '_Nullable' if the pointer may be null
int     sigemptyset(sigset_t *);
                             ^
                              _Nullable
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:89:26: note: insert '_Nonnull' if the pointer should never be null
int     sigemptyset(sigset_t *);
                             ^
                              _Nonnull
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:90:25: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
int     sigfillset(sigset_t *);
                            ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:90:25: note: insert '_Nullable' if the pointer may be null
int     sigfillset(sigset_t *);
                            ^
                             _Nullable
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:90:25: note: insert '_Nonnull' if the pointer should never be null
int     sigfillset(sigset_t *);
                            ^
                             _Nonnull
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:94:32: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
int     sigismember(const sigset_t *, int);
                                   ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:94:32: note: insert '_Nullable' if the pointer may be null
int     sigismember(const sigset_t *, int);
                                   ^
                                    _Nullable
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:94:32: note: insert '_Nonnull' if the pointer should never be null
int     sigismember(const sigset_t *, int);
                                   ^
                                    _Nonnull
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:96:25: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
int     sigpending(sigset_t *);
                            ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:96:25: note: insert '_Nullable' if the pointer may be null
int     sigpending(sigset_t *);
                            ^
                             _Nullable
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:96:25: note: insert '_Nonnull' if the pointer should never be null
int     sigpending(sigset_t *);
                            ^
                             _Nonnull
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:97:37: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
int     sigprocmask(int, const sigset_t * __restrict, sigset_t * __restrict);
                                        ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:97:37: note: insert '_Nullable' if the pointer may be null
int     sigprocmask(int, const sigset_t * __restrict, sigset_t * __restrict);
                                        ^
                                          _Nullable
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:97:37: note: insert '_Nonnull' if the pointer should never be null
int     sigprocmask(int, const sigset_t * __restrict, sigset_t * __restrict);
                                        ^
                                          _Nonnull
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:97:60: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
int     sigprocmask(int, const sigset_t * __restrict, sigset_t * __restrict);
                                                               ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:97:60: note: insert '_Nullable' if the pointer may be null
int     sigprocmask(int, const sigset_t * __restrict, sigset_t * __restrict);
                                                               ^
                                                                 _Nullable
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:97:60: note: insert '_Nonnull' if the pointer should never be null
int     sigprocmask(int, const sigset_t * __restrict, sigset_t * __restrict);
                                                               ^
                                                                 _Nonnull
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:100:31: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
int     sigsuspend(const sigset_t *) __DARWIN_ALIAS_C(sigsuspend);
                                  ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:100:31: note: insert '_Nullable' if the pointer may be null
int     sigsuspend(const sigset_t *) __DARWIN_ALIAS_C(sigsuspend);
                                  ^
                                   _Nullable
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:100:31: note: insert '_Nonnull' if the pointer should never be null
int     sigsuspend(const sigset_t *) __DARWIN_ALIAS_C(sigsuspend);
                                  ^
                                   _Nonnull
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:101:28: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
int     sigwait(const sigset_t * __restrict, int * __restrict) __DARWIN_ALIAS_C(sigwait);
                               ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:101:28: note: insert '_Nullable' if the pointer may be null
int     sigwait(const sigset_t * __restrict, int * __restrict) __DARWIN_ALIAS_C(sigwait);
                               ^
                                 _Nullable
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:101:28: note: insert '_Nonnull' if the pointer should never be null
int     sigwait(const sigset_t * __restrict, int * __restrict) __DARWIN_ALIAS_C(sigwait);
                               ^
                                 _Nonnull
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:101:46: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
int     sigwait(const sigset_t * __restrict, int * __restrict) __DARWIN_ALIAS_C(sigwait);
                                                 ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:101:46: note: insert '_Nullable' if the pointer may be null
int     sigwait(const sigset_t * __restrict, int * __restrict) __DARWIN_ALIAS_C(sigwait);
                                                 ^
                                                   _Nullable
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:101:46: note: insert '_Nonnull' if the pointer should never be null
int     sigwait(const sigset_t * __restrict, int * __restrict) __DARWIN_ALIAS_C(sigwait);
                                                 ^
                                                   _Nonnull
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:103:39: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
void    psignal(unsigned int, const char *);
                                         ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:103:39: note: insert '_Nullable' if the pointer may be null
void    psignal(unsigned int, const char *);
                                         ^
                                          _Nullable
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:103:39: note: insert '_Nonnull' if the pointer should never be null
void    psignal(unsigned int, const char *);
                                         ^
                                          _Nonnull
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:106:31: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
int     sigvec(int, struct sigvec *, struct sigvec *);
                                  ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:106:31: note: insert '_Nullable' if the pointer may be null
int     sigvec(int, struct sigvec *, struct sigvec *);
                                  ^
                                   _Nullable
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:106:31: note: insert '_Nonnull' if the pointer should never be null
int     sigvec(int, struct sigvec *, struct sigvec *);
                                  ^
                                   _Nonnull
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:106:48: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
int     sigvec(int, struct sigvec *, struct sigvec *);
                                                   ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:106:48: note: insert '_Nullable' if the pointer may be null
int     sigvec(int, struct sigvec *, struct sigvec *);
                                                   ^
                                                    _Nullable
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:106:48: note: insert '_Nonnull' if the pointer should never be null
int     sigvec(int, struct sigvec *, struct sigvec *);
                                                   ^
                                                    _Nonnull
220 warnings generated.
clang -bundle -undefined dynamic_lookup -L/usr/local/opt/readline/lib -L/usr/local/opt/readline/lib -L/Users/markkelly/.pyenv/versions/3.8.0/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/readline/lib -L/Users/markkelly/.pyenv/versions/3.8.0/lib build/temp.macosx-10.15-x86_64-3.8/src/DP.o build/temp.macosx-10.15-x86_64-3.8/src/optimum_reparam_N.o -o build/lib.macosx-10.15-x86_64-3.8/optimum_reparam_N.cpython-38-darwin.so
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -I/private/var/folders/pg/g0n4w9955m7ff1rsj6b6tpz40000gn/T/pip-build-env-vgswf17a/overlay/lib/python3.8/site-packages/numpy/core/include -I/Users/markkelly/RedMatter/repos/new_version/cytopy/.venv/include -I/Users/markkelly/.pyenv/versions/3.8.0/include/python3.8 -c src/bayesian.cpp -o build/temp.macosx-10.15-x86_64-3.8/src/bayesian.o
In file included from src/bayesian.cpp:1:
In file included from src/armadillo:26:
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/cmath:317:9: error: no member named 'signbit' in the global namespace
using ::signbit;
      ~~^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/cmath:318:9: error: no member named 'fpclassify' in the global namespace
using ::fpclassify;
      ~~^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/cmath:319:9: error: no member named 'isfinite' in the global namespace; did you mean 'finite'?
using ::isfinite;
      ~~^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/math.h:752:12: note: 'finite' declared here
extern int finite(double)
           ^
In file included from src/bayesian.cpp:1:
In file included from src/armadillo:26:
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/cmath:320:9: error: no member named 'isinf' in the global namespace
using ::isinf;
      ~~^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/cmath:321:9: error: no member named 'isnan' in the global namespace
using ::isnan;
      ~~^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/cmath:322:9: error: no member named 'isnormal' in the global namespace
using ::isnormal;
      ~~^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/cmath:323:9: error: no member named 'isgreater' in the global namespace
using ::isgreater;
      ~~^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/cmath:324:9: error: no member named 'isgreaterequal' in the global namespace
using ::isgreaterequal;
      ~~^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/cmath:325:9: error: no member named 'isless' in the global namespace
using ::isless;
      ~~^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/cmath:326:9: error: no member named 'islessequal' in the global namespace
using ::islessequal;
      ~~^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/cmath:327:9: error: no member named 'islessgreater' in the global namespace
using ::islessgreater;
      ~~^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/cmath:328:9: error: no member named 'isunordered' in the global namespace
using ::isunordered;
      ~~^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/cmath:329:9: error: no member named 'isunordered' in the global namespace
using ::isunordered;
      ~~^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/cmath:640:26: error: no template named 'numeric_limits'
    bool _FloatBigger = (numeric_limits<_FloatT>::digits > numeric_limits<_IntT>::digits),
                         ^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/cmath:640:60: error: no template named 'numeric_limits'
    bool _FloatBigger = (numeric_limits<_FloatT>::digits > numeric_limits<_IntT>::digits),
                                                           ^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/cmath:641:18: error: no template named 'numeric_limits'
    int _Bits = (numeric_limits<_IntT>::digits - numeric_limits<_FloatT>::digits)>
                 ^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/cmath:641:50: error: no template named 'numeric_limits'
    int _Bits = (numeric_limits<_IntT>::digits - numeric_limits<_FloatT>::digits)>
                                                 ^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/cmath:646:17: error: no template named 'numeric_limits'
  static_assert(numeric_limits<_FloatT>::radix == 2, "FloatT has incorrect radix");
                ^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/cmath:649:25: error: no template named 'numeric_limits'
  return _FloatBigger ? numeric_limits<_IntT>::max() :  (numeric_limits<_IntT>::max() >> _Bits << _Bits);
                        ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
setup.py:47: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
  mac_ver = str(LooseVersion(get_config_var('MACOSX_DEPLOYMENT_TARGET')))
not modified: 'build/_DP.c'

这似乎与CommandLineTools有关

编辑

为了跟进Alan下面的评论,当我转到Visual代码>命令调色板> Python: Select解释器时,我会看到以下内容:

编辑遵循@菲尼克斯的答案,我下载并安装了conda。然后我创建了一个虚拟环境:

代码语言:javascript
复制
conda create --name myEnv python=3.8

然后我激活:

代码语言:javascript
复制
conda activate myEnv

正如我看到的(myEnv),它会激活。然后我会:

代码语言:javascript
复制
which python

其中产出:

代码语言:javascript
复制
/usr/local/bin/python

然后我做(在myEnv中):

代码语言:javascript
复制
python --version

其中产出:

代码语言:javascript
复制
Python 3.9.9

当我期待3.8.0的时候。无论如何,我继续并运行(在myEnv中):

代码语言:javascript
复制
pip install numpy==1.19 

它用另一个错误来响应:

代码语言:javascript
复制
ERROR: Could not find a version that satisfies the requirement numpy==1.19 (from versions: 1.3.0, 1.4.1, 1.5.0, 1.5.1, 1.6.0, 1.6.1, 1.6.2, 1.7.0, 1.7.1, 1.7.2, 1.8.0, 1.8.1, 1.8.2, 1.9.0, 1.9.1, 1.9.2, 1.9.3, 1.10.0.post2, 1.10.1, 1.10.2, 1.10.4, 1.11.0, 1.11.1, 1.11.2, 1.11.3, 1.12.0, 1.12.1, 1.13.0rc1, 1.13.0rc2, 1.13.0, 1.13.1, 1.13.3, 1.14.0rc1, 1.14.0, 1.14.1, 1.14.2, 1.14.3, 1.14.4, 1.14.5, 1.14.6, 1.15.0rc1, 1.15.0rc2, 1.15.0, 1.15.1, 1.15.2, 1.15.3, 1.15.4, 1.16.0rc1, 1.16.0rc2, 1.16.0, 1.16.1, 1.16.2, 1.16.3, 1.16.4, 1.16.5, 1.16.6)

当然,numpy 1.19确实存在。

用python建立一个虚拟环境总是非常困难吗?

EN

回答 9

Stack Overflow用户

回答已采纳

发布于 2021-12-24 02:36:55

因此,我要注意的第一件事是,您想要使用的包CytoPy的文档中有一个专门的页面来安装和配置CytoPy。此页面可以访问这里

此页面列出了按顺序必须遵循的各种步骤,包括安装MongoDB安装NumPy和其他步骤。安装过程非常具体和详细,所以我想强调一些重要的事情。首先,您必须确保使用正确的Python版本,即3.8。此外,您希望拥有正确的NumPy版本,即1.19

此外,CytoPy强烈建议使用Conda而不是venv来创建您的环境,在使用包含非Python语言代码的工具(这包括许多数据和科学计算工具,其中包含来自编译语言(如C或C++)的模块)时,这通常是非常好的建议。有关Conda与venv之间的更多差异,请参见这篇文章

此外,虽然这并不是绝对必要的,但如果您计划在将来进行大量的科学计算和基于数据的计算,或者计划将许多不同的包安装到您正在为该项目使用的环境中,我强烈建议您研究一下曼巴,这是一个更快、更好的Conda版本,尽管根据您的具体意图,这个项目可能没有必要这样做。

在更一般的情况下,虽然遵循一般Python教程(比如您从VSCode中提到的教程)当然没有什么问题,但您最好还是研究一下您想要使用的特定包中的更具体的安装过程/建议,以及您所处的计算领域中推荐的“最佳实践”。实际上,在VSCode教程这里中实际上提到了这一点。

数据科学:如果您使用Python的主要目的是数据科学,那么您可以考虑从Anaconda下载。Anaconda不仅提供Python解释器,而且为数据科学提供了许多有用的库和工具。

编辑:编辑的答案,以回应您的更新涉及您的问题与conda。

在以下方面:

输出:which python/usr/local/bin/python

这是问题的根源,即使您已经激活了conda环境,如果python仍然指向那个python解释器,那么您的python别名/路径可能会出现问题。

不幸的是,您的麻烦可能是由conda:https://github.com/conda/conda/issues/9392中已知的bug造成的。

通过阅读上面链接的Github网页,我推荐了两种可能的解决办法(这些解决办法归功于此网页上的开发人员):

解决办法1:

  1. 打开一个新的终端会话。如果您当前处于conda环境中,就像在您的shell会话的左边看到(base)一样,那么跳到步骤2。如果您没有看到(base)类型conda activate来激活conda环境。
  2. 键入conda activate myEnv并按enter以激活myEnv环境。
  3. 输入which python并按enter键,注意使用了错误的python解释器。
  4. 键入conda deactivate以禁用conda环境myEnv
  5. 键入conda deactivate以禁用基本conda环境。
  6. 键入conda activate myEnv以激活conda环境myEnv
  7. 输入which pythonpython -V来验证您是否使用了正确的python解释器和版本。

如果这不起作用,退出shell会话,打开一个新会话,然后尝试以下操作:

变通方法2

这个解决办法有点短,但我对它不太有信心。

  1. 打开一个新的终端外壳,如果没有激活conda基本环境,则激活它。
  2. conda create --name myEnv2 python=3.8 numpy==1.19创建一个新环境(您可能必须对安装numpy的提示符回答是)
  3. 检查which pythonpython -V,看看这是否有效。如果这不起作用,请尝试使用myEnv2而不是myEnv的解决方案1。

将来,在使用conda环境之前,请确保检查当前python是什么,如果不正确,请使用任何适合您的解决方案。

如果没有这些工作,您可以检查这里讨论的其他解决方案,但我认为至少有一个上面的方法应该有效:https://github.com/conda/conda/issues/9392

我完全理解你对创造环境的挫折感。创建和管理python虚拟环境可能很困难(具有讽刺意味的是,这正是conda应该解决的问题),但由于conda中一个未修复的bug,您的情况似乎特别复杂。

票数 3
EN

Stack Overflow用户

发布于 2021-12-23 02:12:53

我认为您试图使用的库支持python3.6和python3.7。我认为默认的全局python版本是2.7,但是您的venv是用python3.8创建的,因此出错了。

尝试使用2.7、3.6或3.7之一的python创建venv,然后再试一次。

我发现:python<version optionally> -m pip install <sth>总是使用适当的笔尖,并且可以节省我很多的挠头和拉头发的时间。

票数 4
EN

Stack Overflow用户

发布于 2021-12-27 16:51:18

在您的虚拟环境中,您需要这样做。

python3 -m pip install -U pip setuptools wheel --ignore-installed

您可能在您的虚拟环境中没有可用的轮子,尽管这在您的系统python中是可用的。

通常,大多数软件包需要安装pipsetuptoolswheel在您的虚拟环境中。他们的最新版本是首选。

默认情况下,venv在虚拟环境中安装pipsetuptools (但不是wheel)。

此外,请参考这个Dockerfile获取有关包安装步骤的更多信息。

您需要安装wheel,并且在您的虚拟环境中丢失了这一点。

用python建立一个虚拟环境总是非常困难吗?

设置虚拟环境很简单,管理依赖项和它们所需的版本不是很简单。这不是python特有的问题,它通常被称为依赖地狱

使用虚拟环境是管理依赖关系问题的一个不完善的解决方案。

多年来,python开发人员创建了许多工具来简化这一工作,virtualenvvenvvirtualenvwrapperpipenvpoetry等是这一领域中最流行的工具。

而且并不总是特别难的。

我对Python很陌生,并且很难理解安装软件包的不同方法。

阅读了有关在 文档中安装python包的更多信息。

一些开发人员使用Docker来代替它。例如,CytoPy github页面

CytoPy有许多复杂的依赖项,因此我们建议您使用docker。

--您可能也应该尝试docker,如果您认为管理依赖关系所需的工作量太大了。

当然,numpy 1.19确实存在。

对于python2,命令pip正在尝试python2。建议的numpy版本是python2兼容版本。

您需要使用pip3python3 -m pip安装python3兼容的numpy版本(至少在您的系统上)。

以及安装CytoPy

代码语言:javascript
复制
python3 -m pip install cytopy
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70427388

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档