4

I am new to Python and struggling to understand the different ways to install packages. I am on MacOS Catalina.

I tried installing the Python package CytoPy (https://github.com/burtonrj/CytoPy) in the terminal:

pip install cytopy

This installs fine. I create a file test.py:

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

Which runs fine, i.e. the cytopy package is imported correctly.

I then follow this Getting Started with Python in Visual Studio tutorial here: https://code.visualstudio.com/docs/python/python-tutorial

It says its important to avoid installing packages into a global interpreter environment and instead use a project-specific virtual environment. I create a virtual environment as per the tutorial in the Terminal within Visual Studio Code:

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

Now, I attempt to install the package in the virtual environment:

pip install cytopy

And I end up with a huge number of errors:

enter image description here

The main error is:

 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

Why does it install globally, but not within the virtual environment via the terminal in Visual Studio Code?

EDIT I used pip3 as suggested. I still get the same error. Here are more logs of the errors:

                                          _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'

It seems to be something to do with CommandLineTools

EDIT

To follow on from a comment below by Alan, when I go to Visual Studio Code > Command Palette > Python: Select Interpreter, I see this:

enter image description here

EDIT Following @Phoenix answer, I downloaded and installed conda. I then created a virtual environment:

conda create --name myEnv python=3.8

I then activate:

conda activate myEnv

It activates as I see (myEnv). I then do:

which python

Which outputs:

/usr/local/bin/python

I then do (within myEnv):

python --version

Which outputs:

Python 3.9.9

When I should expect 3.8.0. Anyway, I proceed and run (within myEnv):

pip install numpy==1.19 

Which responds with yet another error:

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)

Of course, numpy 1.19 does exist.

It is always this extraordinarily hard to set up a virtual environment with python?

dheeraj
  • 43
  • 4
Mark
  • 4,428
  • 14
  • 60
  • 116
  • 1
    Perhaps `pip` uses Python 2, not Python 3, so you get different Python versions globally and in the virtual environment. – md2perpe Dec 20 '21 at 20:12
  • Check you don't have multiple versions of python3 installed - and what version. It's uncommon but not impossible. A lot of C/C++ based packages take a while to be ported to the latest versions of Python and downgrading helps. Your system python may vary from the venv one, or you may have a dependency / config already on your system that's not in the venv. – Alan Dec 21 '21 at 08:47
  • @Alan yes I do seem to have many version, check my edit – Mark Dec 21 '21 at 09:19
  • Can you check if the package is available for both versions? – ashutosh singh Dec 22 '21 at 23:18
  • Strange for me inside a venv it says it can't find cytopy. – ashutosh singh Dec 22 '21 at 23:29
  • I think the problem is with venv. Have you tried with conda env? It's definitely not working inside a venv. So your setup is not a problem – ashutosh singh Dec 22 '21 at 23:31
  • It seems there are multiple errors (due to overhead generated by trying several suggestions). Going back to the **original error** please specify your *Python* version that fails (and you want it to succeed), the one that succeeds and your *CLang* version (`clanv -v`). – CristiFati Dec 28 '21 at 15:18
  • you try conda install xxxx. – lazy Dec 29 '21 at 08:16
  • I faced a similar issue while installing opencv for python. Then I decided to use docker for the development environment and it was the best decision. A simple Dockerfile enables a repeatable and consistent environment. New developers can also start working on the project quickly. Virtual environments are very good but it gets really dirty for packages with complex dependencies. – Ahmet Dec 29 '21 at 13:13

9 Answers9

4

I think the library you are trying to use is supported on python3.6 and python3.7. I think your default global python version is 2.7, but your venv was created with python3.8, hence error.

Try creating venv with one of 2.7, 3.6 or 3.7 python and try again.

I found that: python<version optionally> -m pip install <sth> always uses proper pip and saves me a lot of head scratching and hair pulling.

yjay
  • 942
  • 4
  • 11
3

So the first thing I want to note is that the documentation of the package you want to use, CytoPy, has a dedicated page to installing and configuring CytoPy. This page can be accessed here.

This page lists the various steps that must be followed in order, including installing MongoDB, installing NumPy, and other steps. The installation process is very specific and detailed, so I want to highlight a few things which are important. Firstly, you must make sure to use the proper version of Python, namely 3.8. Further, you want to have the correct version of NumPy, namely 1.19.

Further, CytoPy strongly recommends creating your environments using Conda instead of venv, which in general is very good advice when using tools which contain code from non-Python languages (which includes many data and scientific computing tools which contain modules from compiled languages such as C or C++). For more differences on Conda vs venv see this article.

In addition, while this is not strictly necessary, if you plan on doing a lot of scientific computing and data-based computing in the future or you plan on installing many different packages into the environment you are using for this project, I would strongly recommend looking into Mamba, which is a faster, improved version of Conda, although this may not be necessary for this project depending on your specific intentions.

On a more general note, while there is of course nothing wrong with following general Python tutorials such as the one you mentioned from VSCode, you are often better off looking into the more specific installation processes/recommendations from the specific packages you want to use and the recommended "best practices" for the area of computing you are in. In fact, this is actually mentioned in the VSCode tutorial here:

Data Science: If your primary purpose for using Python is Data Science, then you might consider a download from Anaconda. Anaconda provides not just a Python interpreter, but many useful libraries and tools for data science.

Edit: Edited answer in response to your update involving your issues with conda.

In regards to the following:

which python Which outputs: /usr/local/bin/python

This here is the root of your issue, if python still points to that python interpreter even when you have activated your conda environment, it is likely a problem with your python aliasing/PATH.

Unfortunately your trouble is likely the result of a known bug in conda: https://github.com/conda/conda/issues/9392

From reading through the Github webpage linked above there are two potential workarounds I recommend (credit to the developers on this webpage for these workarounds):

Workaround 1:

  1. Open a new terminal session. If you are currently in a conda base environment, as in you see (base) to the left of your shell session, then skip to step 2. If you did not see (base) type conda activate to activate the conda base environment.

  2. Type conda activate myEnv and press enter to activate the myEnv environment.

  3. Type which python and press enter, noting that you are using the wrong python interpreter.

  4. Type conda deactivate to deactivate the conda environment myEnv

  5. Type conda deactivate to deactivate the base conda environment.

  6. Type conda activate myEnv to activate the conda environment myEnv.

  7. Type which python and python -V to verify you are using the correct python interpreter and version.

If this does not work, exit the shell session, open a new one and try the following:

Workaround 2

This workaround is a bit shorter but I am less confident in it.

  1. Open a new terminal shell and activate conda base environment if it is not already activated.

  2. Create a new environment with conda create --name myEnv2 python=3.8 numpy==1.19 (you may have to answer yes to a prompt to install numpy)

  3. Check which python and python -V to see if this works. If this does not work, try using workaround 1 with myEnv2 instead of myEnv.

In the future, before using your conda environments make sure to check what the current python is and if it is not correct use whichever workaround worked for you.

If none of these work, you can examine the other workarounds discussed here but I believe at least 1 of the above should work: https://github.com/conda/conda/issues/9392

I totally understand your frustration with creating your environment. Creating and managing python virtual environments can be difficult (ironically this was what conda was supposed to solve), but it seems that your case is particularly complicated due to an unfixed bug in conda.

Phoenix
  • 952
  • 2
  • 12
  • Thanks. I tried conda, many many more errors. See my edit. – Mark Dec 26 '21 at 21:36
  • @Mark please see my edited answer above. Hopefully these workarounds or the others I linked to work for you. This is definitely frustrating. – Phoenix Dec 27 '21 at 04:10
  • 1
    Thank you, amazing answer and that worked! You deserve the bonus points but it got automatically awarded elsewhere as didnt log in in time. Sorry:/ – Mark Dec 31 '21 at 19:40
  • @Mark No worries I am glad I was able to help you resolve your issue – Phoenix Dec 31 '21 at 20:03
1

Within your virtual environment you need to do

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

You might not have wheel available in your virtual environment although that may be available in your system python.

Generally, most packages need pip, setuptools and wheel in your virtual environment to install. Their latest versions are to be preferred.

venv installs pip and setuptools by default in the virtual environment (but not wheel).


Also, refer this Dockerfile to get more information about the package install steps.

You need to install wheel and you are missing that in your virtual environment.


It is always this extraordinarily hard to set up a virtual environment with python?

Setting up a virtual environment is straightforward, managing dependencies and their required versions is not. This is not a python specific issue and it is commonly known as dependency hell.

Using virtual environments is an imperfect solution to the problem of managing dependencies.

Over the years python developers have created many tools to make this easier, virtualenv, venv, virtualenvwrapper, pipenv, poetry, etc are popular tools in this space.

And it's not always extraordinarily hard.


I am new to Python and struggling to understand the different ways to install packages.

Read more about installing python packages in the docs


Some developers use Docker instead to do this. for instance the CytoPy github page says

CytoPy has many complex dependencies, therefore we recommend that you use docker.

You should probably try docker as well, if you decide the effort required to manage dependencies is too much.


Of course, numpy 1.19 does exist.

Not for python2, the command pip is trying python2. The versions of numpy suggested are python2 compatible versions.

You need to use either pip3 or python3 -m pip to install python3 compatible version of numpy (at least on your system)

And to install CytoPy

python3 -m pip install cytopy

dheeraj
  • 43
  • 4
0

Your env is python3 and pip on mac is python2. I think. Try and use pip3 for the install or run your env in python2. Might be using different python verions.

B.Quinn
  • 77
  • 1
  • 7
0

I suggest you use pipenv as you are first time using virtual environment.

Follow these steps:

  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. test your code python -c "from cytopy.data.setup import global_init"

Note: CFLAGS="$CFLAGS -Wno-implicit-function-declaration" in step 4 is because I found the project have some c implicit declaration compile error, so use this to ignore that.

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." This means they didn't ensure macos not have problem.

Next time your want activate your virtual environment, just repeat the first two steps.

When you are used to virtual environment, you can try other virtual environment solutions.

Xu Qiushi
  • 1,111
  • 1
  • 5
  • 10
0

use python:3.6-slim docker image, fix it by installing gcc inside the container.

go to enter link description here

minabagheri
  • 541
  • 2
  • 9
0

Taken from this StackOverflow post by a pip maintainer,

Trying to build a wheel can fail if you no longer have the wheel package. Make sure to install wheel with the following possible commands.

Option 1: pip install wheel

Option 2: pip3 install wheel

Option 3: python -m pip install wheel

Option 4: python3 -m pip install wheel

theheavycoder
  • 337
  • 3
  • 11
0

You can use where python command in cmd to find the path that python is installed in. then you can use this command -

[python path] -m pip install package
Tal Folkman
  • 2,368
  • 1
  • 7
  • 21
0

You need to use Python 3.8 interpreter inside your virtual environment.

Inside of your virtual environment you need to have installed wheel and setuptools to check this execute this command:
pip3 list

If you don't have them installed execute the following command:
pip3 install setuptools wheel

After this, you can install CytoPy with these commands:
pip3 install numpy==1.19
pip3 install cytopy

These instructions work for me inside a virtual environment.

I haven't gotten it to work with Python 3.9, because there were dependency problems.

On the other hand I recommend you to install CitoPy following the instructions from the official documentation or use the docker image that they provided.