繁体   English   中英

Python package 全局安装,但在虚拟环境中失败

[英]Python package installs globally but fails within virtual environment

我是 Python 的新手,并且很难理解安装软件包的不同方法。 我在 MacOS Catalina 上。

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

pip install cytopy

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

from cytopy.data.setup import global_init
print("test")

哪个运行良好,即正确导入细胞 package。

然后,我在此处的 Visual Studio 教程中遵循 Python 入门: https://code.visualstudio.com/docs/python/python-tutorial

它说避免将包安装到全局解释器环境中并使用特定于项目的虚拟环境很重要。 我根据 Visual Studio Code 中终端中的教程创建了一个虚拟环境:

python3 -m venv .venv
source .venv/bin/activate

现在,我尝试在虚拟环境中安装 package:

pip install cytopy

我最终会遇到大量错误:

在此处输入图像描述

主要错误是:

 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 Studio Code 中的终端在虚拟环境中安装?

编辑我按照建议使用了 pip3 。 我仍然得到同样的错误。 以下是更多错误日志:

                                          _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 下面的评论开始,当我 go 到 Visual Studio Code > Command Palette > Python: Select 解释器时,我看到了这个:

在此处输入图像描述

编辑在@Phoenix 回答之后,我下载并安装了conda。 然后我创建了一个虚拟环境:

conda create --name myEnv python=3.8

然后我激活:

conda activate myEnv

如我所见(myEnv),它会激活。 然后我做:

which python

哪个输出:

/usr/local/bin/python

然后我做(在myEnv中):

python --version

哪个输出:

Python 3.9.9

当我应该期待 3.8.0. 无论如何,我继续并运行(在 myEnv 中):

pip install numpy==1.19 

它响应另一个错误:

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 搭建虚拟环境总是这么难?

我认为您尝试使用的库在 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>总是使用正确的 pip 并为我节省了很多头抓挠和头发拉扯。

你的环境是python3,mac上的pip是python2。 我认为。 尝试使用 pip3 进行安装或在 python2 中运行您的环境。 可能正在使用不同的 python 版本。

所以我首先要注意的是,您要使用的 package 的文档 CytoPy 有一个专门的页面来安装和配置 CytoPy。 这个页面可以在这里访问。

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

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

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

更一般地说,虽然遵循一般 Python 教程(例如您在VSCode中提到的教程)当然没有错,但您通常最好从您要使用的特定软件包中查看更具体的安装过程/建议,并且为您所在的计算领域推荐的“最佳实践”。事实上,这实际上是在 VSCode 教程中提到

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

我建议您使用 pipenv,因为您是第一次使用虚拟环境。

按着这些次序:

  1. pip3 install pipenv
  2. cd YOUR_PROJECT_DIR
  3. pipenv shell
  4. CFLAGS="$CFLAGS -Wno-implicit-function-declaration" pipenv install --skip-lock numpy="==1.19.0" cytopy
  5. 测试你的代码python -c "from cytopy.data.setup import global_init"

注意:步骤 4 中CFLAGS="$CFLAGS -Wno-implicit-function-declaration"是因为我发现项目有一些 c 隐式声明编译错误,所以用这个忽略它。

By the way, on their website they say "CytoPy is cross-platform compatible but has been tested on Windows 10, Ubuntu 20.04, and Ubuntu 18.04. If you experience issues on other platforms please raise an issue on GitHub." 这意味着他们不能确保 macos 没有问题。

下次您想激活虚拟环境时,只需重复前两个步骤。

当您习惯了虚拟环境时,您可以尝试其他虚拟环境解决方案。

使用python:3.6-slim docker 映像,通过在容器内安装gcc来修复它。

go 在此处输入链接描述

取自pip 维护者的这篇 StackOverflow 帖子

如果您不再拥有轮子 package,则尝试构建轮子可能会失败。 确保使用以下可能的命令安装 wheel。

方案一: pip install wheel

选项2: pip3 install wheel

选项3: python -m pip install wheel

选项4: python3 -m pip install wheel

在您需要做的虚拟环境中

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

尽管您的系统 python 中可能提供了 wheel 和 setuptools,但您的虚拟环境中可能没有可用的工具。


此外,请参阅此 Dockerfile以获取有关 package 安装步骤的更多信息。


用 python 搭建虚拟环境总是这么难?

设置虚拟环境很简单,管理依赖项及其所需版本则不然。

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

多年来,python 开发人员创建了许多工具来简化此操作, virtualenvvenvvirtualenvwrapperpipenvpoetry等是该领域的流行工具。

一些开发人员使用 Docker 代替执行此操作。 例如CytoPy github 页面

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

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


您可以使用 cmd 中的where python命令找到安装 python 的路径。然后您可以使用此命令 -

[python path] -m pip install package

您需要在虚拟环境中使用Python 3.8解释器。

在您的虚拟环境中,您需要安装wheelsetuptools来检查是否执行此命令:
pip3 list

如果您没有安装它们,请执行以下命令:
pip3 install setuptools wheel

在此之后,您可以使用以下命令安装 CytoPy:
pip3 install numpy==1.19
pip3 install cytopy

这些说明在虚拟环境中对我有用。

我还没有让它与 Python 3.9 一起使用,因为存在依赖性问题。

另一方面,我建议您按照官方文档中的说明安装 CitoPy 或使用他们提供的docker 映像

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM