【anaconda3】 ubuntu18.04下sudo: conda: command not found

在Ubuntu18.04环境下,安装Anaconda3后遇到使用sudo执行conda命令失败的问题。解决方法包括在使用sudo时临时指定PATH环境变量或在.bashrc文件中设置别名。通过编辑.bashrc并source使其生效后,成功创建了python3虚拟环境。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

【python初级】 ubuntu18.04下sudo: conda: command not found

1、背景

在ubuntu18.04下安装Anaconda3-2020.02-Linux-x86_64.sh
对应的conda版本:4.8.2

Sun@Sunt:~/Sun-public/softwarePakages$ conda -V
conda 4.8.2
Sun@Sunt:~/Sun-public/softwarePakages$ conda info --e
# conda environments:
#
base                  *  /home/Sun/Sun-public/install/Anaconda3-2020.02

安装anconda3之后,使用ancoda3创建python3虚拟环境报错:

Sun@Sunt:~/Sun-public/softwarePakages$ sudo conda create -n dllng python=3.6
sudo: conda: command not found

2、解决办法

编译sudo的时候加入了–with-secure-path 选项。
两种解决方案:
方法1(临时)每次在使用sudo命令的时候使用:sudo env “PATH=$PATH” xxx

sudo  env "PATH=$PATH" conda create -n dllng python=3.6

方法2(永久)在环境配置文件里加一个alias
首先
vim ~/.bashrc
添加如下内容:

alias sudo="sudo env PATH=$PATH"

然后:
source ~/.bashrc

3、验证


Sun@Sunt:~/Sun-public/softwarePakages$ vim  ~/.bashrc
Sun@Sunt:~/Sun-public/softwarePakages$ source ~/.bashrc

(base) Sun@Sunt:~/Sun-public/softwarePakages$ sudo conda create -n dllng python=3.6
Collecting package metadata (current_repodata.json): done
Solving environment: done

==> WARNING: A newer version of conda exists. <==
  current version: 4.8.2
  latest version: 4.10.3
Please update conda by running
    $ conda update -n base -c defaults conda
## Package Plan ##
  environment location: /home/Sun/Sun-public/install/Anaconda3-2020.02/envs/dllng
  added / updated specs:
    - python=3.6
The following packages will be downloaded:
    package                    |            build
    ---------------------------|-----------------
    _openmp_mutex-4.5          |            1_gnu          22 KB
    ca-certificates-2021.7.5   |       h06a4308_1         113 KB
    certifi-2021.5.30          |   py36h06a4308_0         139 KB
    ld_impl_linux-64-2.35.1    |       h7274673_9         586 KB
    libffi-3.3                 |       he6710b0_2          50 KB
    libgcc-ng-9.3.0            |      h5101ec6_17         4.8 MB
    libgomp-9.3.0              |      h5101ec6_17         311 KB
    libstdcxx-ng-9.3.0         |      hd4cf53a_17         3.1 MB
    ncurses-6.2                |       he6710b0_1         817 KB
    openssl-1.1.1k             |       h27cfd23_0         2.5 MB
    pip-21.0.1                 |   py36h06a4308_0         1.8 MB
    python-3.6.13              |       h12debd9_1        32.5 MB
    readline-8.1               |       h27cfd23_0         362 KB
    setuptools-52.0.0          |   py36h06a4308_0         724 KB
    sqlite-3.36.0              |       hc218d9a_0         990 KB
    tk-8.6.10                  |       hbc83047_0         3.0 MB
    wheel-0.37.0               |     pyhd3eb1b0_0          32 KB
    xz-5.2.5                   |       h7b6447c_0         341 KB
    ------------------------------------------------------------
                                           Total:        52.1 MB
The following NEW packages will be INSTALLED:
  _libgcc_mutex      pkgs/main/linux-64::_libgcc_mutex-0.1-main
  _openmp_mutex      pkgs/main/linux-64::_openmp_mutex-4.5-1_gnu
  ca-certificates    pkgs/main/linux-64::ca-certificates-2021.7.5-h06a4308_1
  certifi            pkgs/main/linux-64::certifi-2021.5.30-py36h06a4308_0
  ld_impl_linux-64   pkgs/main/linux-64::ld_impl_linux-64-2.35.1-h7274673_9
  libffi             pkgs/main/linux-64::libffi-3.3-he6710b0_2
  libgcc-ng          pkgs/main/linux-64::libgcc-ng-9.3.0-h5101ec6_17
  libgomp            pkgs/main/linux-64::libgomp-9.3.0-h5101ec6_17
  libstdcxx-ng       pkgs/main/linux-64::libstdcxx-ng-9.3.0-hd4cf53a_17
  ncurses            pkgs/main/linux-64::ncurses-6.2-he6710b0_1
  openssl            pkgs/main/linux-64::openssl-1.1.1k-h27cfd23_0
  pip                pkgs/main/linux-64::pip-21.0.1-py36h06a4308_0
  python             pkgs/main/linux-64::python-3.6.13-h12debd9_1
  readline           pkgs/main/linux-64::readline-8.1-h27cfd23_0
  setuptools         pkgs/main/linux-64::setuptools-52.0.0-py36h06a4308_0
  sqlite             pkgs/main/linux-64::sqlite-3.36.0-hc218d9a_0
  tk                 pkgs/main/linux-64::tk-8.6.10-hbc83047_0
  wheel              pkgs/main/noarch::wheel-0.37.0-pyhd3eb1b0_0
  xz                 pkgs/main/linux-64::xz-5.2.5-h7b6447c_0
  zlib               pkgs/main/linux-64::zlib-1.2.11-h7b6447c_3
Proceed ([y]/n)? y
Downloading and Extracting Packages
ncurses-6.2          | 817 KB    | ################################################################################## | 100% 
ca-certificates-2021 | 113 KB    | ################################################################################## | 100% 
libffi-3.3           | 50 KB     | ################################################################################## | 100% 
_openmp_mutex-4.5    | 22 KB     | ################################################################################## | 100% 
libgcc-ng-9.3.0      | 4.8 MB    | ################################################################################## | 100% 
wheel-0.37.0         | 32 KB     | ################################################################################## | 100% 
pip-21.0.1           | 1.8 MB    | ################################################################################## | 100% 
certifi-2021.5.30    | 139 KB    | ################################################################################## | 100% 
tk-8.6.10            | 3.0 MB    | ################################################################################## | 100% 
readline-8.1         | 362 KB    | ################################################################################## | 100% 
sqlite-3.36.0        | 990 KB    | ################################################################################## | 100% 
xz-5.2.5             | 341 KB    | ################################################################################## | 100% 
setuptools-52.0.0    | 724 KB    | ################################################################################## | 100% 
libstdcxx-ng-9.3.0   | 3.1 MB    | ################################################################################## | 100% 
ld_impl_linux-64-2.3 | 586 KB    | ################################################################################## | 100% 
libgomp-9.3.0        | 311 KB    | ################################################################################## | 100% 
openssl-1.1.1k       | 2.5 MB    | ################################################################################## | 100% 
python-3.6.13        | 32.5 MB   | ################################################################################## | 100% 
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
#     $ conda activate dllng
#
# To deactivate an active environment, use
#
#     $ conda deactivate

(base) Sun@Sunt:~/Sun-public/softwarePakages$ conda info --e
# conda environments:
#
base                  *  /home/Sun/Sunl-public/install/Anaconda3-2020.02
dllng                    /home/Sun/Sun-public/install/Anaconda3-2020.02/envs/dllng
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

jn10010537

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值