Use python source code to build a conda environment

今天需要使用 python 2.6.8 的环境,发现 conda 设置成清华源后,没有旧版本了。所以打算从官网上下载一份 python 进行安装,
结果发现,conda 不能直接安装离线包(也可能我没找到方法),经过一番尝试终于解决了,这里记录一下。

After downloading and unzipping, execute in the source code directory

./configure -h

You can see a bunch of configuration parameters, most of which we don't need to care about. In order to prevent the newly compiled python from contaminating the existing environment variables of the system, you only need to set the --prefix parameter (that is, the storage location of the compiled python. Note: This parameter requires an absolute path. I created a new folder in the current directory. :268). After understanding these, just execute the following commands in sequence:

./configure --prefix /xxx/xxx/268
make
conda create -n py268 --offline

After executing the above command, a python program will be generated in the 268 folder and a conda py268 environment will be created. However, the current py268 still uses the system's default python environment. You need to copy the contents of the 268 folder to conda's xxx/ envs/py268 folder, and then execute the following command to install pip of py268:

conda activate py268
python -m ensurepip --upgrade

Then restart the command line and use pip in the py268 environment. It is py268's own pip instead of using the default one.

In addition, after installation, I found that there are historical versions in the anaconda environment (which can be viewed through conda search python), so I also posted the anaconda configuration file (obtained through conda config --show) here, mainly The channels configuration inside.

conda config:

add_anaconda_token: True
add_pip_as_python_dependency: True
aggressive_update_packages:
  - ca-certificates
  - certifi
  - openssl
allow_conda_downgrades: False
allow_cycles: True
allow_non_channel_urls: False
allow_softlinks: False
always_copy: False
always_softlink: False
always_yes: None
anaconda_upload: None
auto_activate_base: True
auto_stack: 0
auto_update_conda: True
bld_path: 
changeps1: True
channel_alias: https://conda.anaconda.org
channel_priority: flexible
channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
  - defaults
client_ssl_cert: None
client_ssl_cert_key: None
clobber: False
conda_build: {}
create_default_packages: []
croot: /home/xxx/anaconda3/conda-bld
custom_channels:
  pkgs/main: https://repo.anaconda.com
  pkgs/r: https://repo.anaconda.com
  pkgs/pro: https://repo.anaconda.com
custom_multichannels:
  defaults: 
    - https://repo.anaconda.com/pkgs/main
    - https://repo.anaconda.com/pkgs/r
  local: 
debug: False
default_channels:
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
default_python: 3.8
default_threads: None
deps_modifier: not_set
dev: False
disallowed_packages: []
download_only: False
dry_run: False
enable_private_envs: False
env_prompt: ({default_env}) 
envs_dirs:
  - /home/xxx/anaconda3/envs
  - /home/xxx/.conda/envs
error_upload_url: https://conda.io/conda-post/unexpected-error
execute_threads: 1
extra_safety_checks: False
force: False
force_32bit: False
force_reinstall: False
force_remove: False
ignore_pinned: False
json: False
local_repodata_ttl: 1
migrated_channel_aliases: []
migrated_custom_channels: {}
non_admin_enabled: True
notify_outdated_conda: True
offline: False
override_channels_enabled: True
path_coxxxict: clobber
pinned_packages: []
pip_interop_enabled: False
pkgs_dirs:
  - /home/xxx/anaconda3/pkgs
  - /home/xxx/.conda/pkgs
proxy_servers: {}
quiet: False
remote_backoff_factor: 1
remote_connect_timeout_secs: 9.15
remote_max_retries: 3
remote_read_timeout_secs: 60.0
repodata_fns:
  - current_repodata.json
  - repodata.json
repodata_threads: None
report_errors: None
restore_free_channel: False
rollback_enabled: True
root_prefix: /home/xxx/anaconda3
safety_checks: warn
sat_solver: pycosat
separate_format_cache: False
shortcuts: True
show_channel_urls: True
signing_metadata_url_base: https://repo.anaconda.com/pkgs/main
solver_ignore_timestamps: False
ssl_verify: True
subdir: linux-64
subdirs:
  - linux-64
  - noarch
target_prefix_override: 
track_features: []
unsatisfiable_hints: True
unsatisfiable_hints_check_depth: 2
update_modifier: update_specs
use_index_cache: False
use_local: False
use_only_tar_bz2: False
verbosity: 0
verify_threads: 1
whitelist_channels: []

Guess you like

Origin blog.csdn.net/niuzhucedenglu/article/details/132536804