Skip to content

Commit acee9d4

Browse files
committed
address comments
1 parent 171618d commit acee9d4

File tree

1 file changed

+87
-32
lines changed

1 file changed

+87
-32
lines changed

docs/users-guide/modelsetup.rst

Lines changed: 87 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ Install UV
139139
We recommend installing UV as an independent tool on your machine, separate from any existing package managers you may have such as conda or pip.
140140

141141
For Windows users, run the following command in PowerShell to install *uv*. It does not require administrator privileges and installs *uv* for the current user only.
142-
By default, uv is installed to `~/.local/bin` directory. Usually, this is `C:/Users/<username>/.local/bin`.
142+
By default, uv is installed to ``~/.local/bin`` directory. Usually, this is ``C:/Users/<username>/.local/bin``.
143143

144144
::
145145

@@ -153,11 +153,11 @@ If an agency wants to install *uv* globally for all users on Windows, run PowerS
153153

154154
::
155155

156-
# Run the installer with a custom install directory
157-
powershell -ExecutionPolicy ByPass -c {$env:UV_INSTALL_DIR = "C:\custom\install\directory";irm https://astral.sh/uv/install.ps1 | iex}
156+
# Run the installer with a custom install directory (e.g., C:\shared\uv) that is accessible to all users
157+
powershell -ExecutionPolicy ByPass -c {$env:UV_INSTALL_DIR = "C:\shared\uv";irm https://astral.sh/uv/install.ps1 | iex}
158158

159159
# Add uv to PATH for all users (requires administrator privileges)
160-
[Environment]::SetEnvironmentVariable("PATH", $env:PATH + ";C:\custom\install\directory", [EnvironmentVariableTarget]::Machine)
160+
[Environment]::SetEnvironmentVariable("PATH", $env:PATH + ";C:\shared\uv", [EnvironmentVariableTarget]::Machine)
161161

162162
For more instructions on installing *uv* on Windows, MacOS, or Linux, please visit https://docs.astral.sh/uv/getting-started/installation/.
163163

@@ -221,16 +221,16 @@ Open Command Prompt (not Anaconda Prompt), and run the following commands.
221221
# add ActivitySim package from the latest release on PyPI
222222
uv add activitysim
223223

224-
*uv* will create a new virtual environment within the `asim_project` project folder
224+
*uv* will create a new virtual environment within the ``asim_project`` project folder
225225
and install ActivitySim and its dependencies. The virtual environment is a hidden folder
226-
within the `asim_project` directory called `.venv` and operates the same way as Python's classic *venv*. You will notice
227-
two new files created in the `asim_project` directory: `pyproject.toml` and `uv.lock`. These files
228-
are automatically created, updated, and used by *uv* to manage your `asim_project` project and its dependencies.
229-
You can share these files with others to recreate the same environment for your `asim_project` project. For more guidance on sharing your working environment,
226+
within the ``asim_project`` directory called ``.venv`` and operates the same way as Python's classic *venv*. You will notice
227+
two new files created in the ``asim_project`` directory: ``pyproject.toml`` and ``uv.lock``. These files
228+
are automatically created, updated, and used by *uv* to manage your ``asim_project`` project and its dependencies.
229+
You can share these files with others to recreate the same environment for your ``asim_project`` project. For more guidance on sharing your working environment,
230230
see the Common Q&A :ref:`How to share my working environment with others?` section below.
231231

232-
By running the command `uv add activitysim`, you install the official release of ActivitySim from PyPI and its direct dependencies
233-
listed in ActivitySim's `pyproject.toml` file. This approach is the quickest
232+
By running the command ``uv add activitysim``, you install the official release of ActivitySim from PyPI and its direct dependencies
233+
listed in ActivitySim's ``pyproject.toml`` file. This approach is the quickest
234234
for getting started but it does not rely on ActivitySim's own lockfile to install deep dependencies so you may
235235
end up with different versions of deep dependencies than those tested by ActivitySim developers.
236236
If you want to ensure exact versions of ActivitySim's deep dependencies, you should install ActivitySim using Option 2: From Source with Lockfile.
@@ -247,10 +247,10 @@ instructions can be found `here <https://git-scm.com/downloads>`_.)
247247
git clone https://github.com/ActivitySim/activitysim.git
248248
cd activitysim
249249

250-
Run the `uv sync --locked` command to create a virtual environment using the lockfile. It will initialize a virtual environment within the `activitysim` directory
251-
and install ActivitySim and all its dependencies exactly as specified in the `uv.lock` file.
250+
Run the ``uv sync --locked`` command to create a virtual environment using the lockfile. It will initialize a virtual environment within the ``activitysim`` directory
251+
and install ActivitySim and all its dependencies exactly as specified in the ``uv.lock`` file.
252252
The virtual environment is a hidden folder within the current directory called
253-
`.venv` and operates the same way as Python's classic *venv*.
253+
``.venv`` and operates the same way as Python's classic *venv*.
254254

255255
::
256256

@@ -259,16 +259,16 @@ The virtual environment is a hidden folder within the current directory called
259259

260260
It is worth pointing out that by default, *uv* installs projects in
261261
editable mode, such that changes to the source code are immediately reflected
262-
in the environment. `uv sync` accepts a `--no-editable`
262+
in the environment. ``uv sync`` accepts a ``--no-editable``
263263
flag, which instructs *uv* to install the project in non-editable mode,
264264
removing any dependency on the source code.
265265

266-
Also, `uv sync` automatically installs the dependencies listed in `pyproject.toml`
267-
under `dependencies` under `[project]`, and it also installs those listed
268-
under `dev` under `[dependency-groups]`. If you want to
266+
Also, ``uv sync`` automatically installs the dependencies listed in ``pyproject.toml``
267+
under ``dependencies`` under ``[project]``, and it also installs those listed
268+
under ``dev`` under ``[dependency-groups]``. If you want to
269269
skip the dependency groups entirely with a *uv* install (and only install those
270-
that would install via `pip` from 'pypi`), use the `--no-default-groups` flag
271-
with `uv sync`.
270+
that would install via ``pip`` from ``pypi``), use the ``--no-default-groups`` flag
271+
with ``uv sync``.
272272

273273

274274
Which Option Should I Use?
@@ -305,7 +305,7 @@ Activate the virtual environment created by *uv*. This option is similar to usin
305305
# Activate the virtual environment
306306
.venv\Scripts\activate
307307

308-
Once the virtual environment is activated, you can run ActivitySim commands directly using the `activitysim` command.
308+
Once the virtual environment is activated, you can run ActivitySim commands directly using the ``activitysim`` command.
309309
For example, run the ActivitySim commandline using the following. More information about the commandline interface is available in
310310
the :ref:`Ways to Run the Model` section.
311311

@@ -323,7 +323,7 @@ Common Q&A
323323
^^^^^^^^^^^^^^^^
324324
My travel demand model requires additional Python packages not included with ActivitySim. How do I add them?
325325
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
326-
You can add additional packages to your *uv* project by using the `uv add` command. For example, to add the `geopandas` package,
326+
You can add additional packages to your *uv* project by using the ``uv add`` command. For example, to add the ``geopandas`` package,
327327
run the following command within your existing *uv* project directory.
328328

329329
::
@@ -334,7 +334,7 @@ run the following command within your existing *uv* project directory.
334334
# Add geopandas package
335335
uv add geopandas
336336

337-
This will add the package to your virtual environment and update the `pyproject.toml` and the `uv.lock` file to include the new package and its dependencies.
337+
This will add the package to your virtual environment and update the ``pyproject.toml`` and the ``uv.lock`` file to include the new package and its dependencies.
338338

339339
If you envision having a version of Python packages that is different from the one used by ActivitySim, e.g., you need pandas 1.x for visualization (for some reason),
340340
we recommend creating a separate *uv* project for your custom packages and managing them independently from ActivitySim.
@@ -358,11 +358,23 @@ In such cases, we also recommend creating a separate *uv* project for the commer
358358
uv init --python 2.7
359359
# Then copy the emme.pth file (provides EMME API handshakes) from the Emme installation directory to emme_project/.venv/Lib/site-packages/
360360

361+
When having multiple *uv* projects, you can switch between them by activating the respective virtual environments.
362+
363+
::
364+
365+
# Activate visualization project
366+
# Open Command Prompt
367+
cd path\to\viz_project
368+
.venv\Scripts\activate
369+
370+
# Deactivate visualization project
371+
deactivate
372+
361373
How to share my working environment with others?
362374
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
363-
You can share your working environment with others by sharing the `uv.lock` file and the `pyproject.toml` file located in your project directory.
364-
The `uv.lock` file contains the exact versions of all packages and dependencies used in your project.
365-
Others can recreate the same environment by running the `uv sync --locked` command in a new project directory containing the shared files.
375+
You can share your working environment with others by sharing the ``uv.lock`` file and the ``pyproject.toml`` file located in your project directory (and ``.python-version`` file if it exists).
376+
The ``uv.lock`` file contains the exact versions of all packages and dependencies used in your project.
377+
Others can recreate the same environment by running the ``uv sync --locked`` command in a new project directory containing the shared files.
366378

367379
::
368380

@@ -380,19 +392,62 @@ Others can recreate the same environment by running the `uv sync --locked` comma
380392
# Recreate the same environment
381393
uv sync --locked
382394

395+
Can other users on the same server or machine use my already created virtual environment?
396+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
397+
This is doable but it requires additional setup and admin rights - therefore we do not generally recommend it. We recommend following the practice in :ref:`How to share my working environment with others?`.
398+
399+
If you'd still like to proceed, here are the recommended steps to follow (proceed with caution!):
400+
401+
1. Ensure that you installed UV globally (requires admin rights) on the server/machine for all users. :ref:`Install UV` section above provides instructions on how to do this.
402+
403+
2. Assuming you installed UV globally in ``C:\shared\uv\``, ensure that all users have read and execute permissions to this directory.
404+
405+
3. Create a directory under ``C:\shared\uv\`` to install Python globally for UV. For example, open Command Prompt, create a directory named ``uv_python`` under ``C:\shared\uv\``.
406+
407+
::
408+
409+
cd C:\shared\uv\
410+
mkdir uv_python
411+
412+
4. Under Environment Variables > System variables (requires Admin), create a new system environment variable named ``UV_PYTHON_INSTALL_DIR`` and set its value to the Python directory created in step 3 ``C:\shared\uv\uv_python\``.
413+
414+
5. Run the following command to install Python globally for UV. This should install Python executables globally in the ``UV_PYTHON_INSTALL_DIR`` directory.
415+
416+
::
417+
418+
uv python install 3.10
419+
420+
6. Under Environment Variables > System variables (requires Admin), create a new system environment variable named ``UV_PYTHON`` and set its value to the ``python.exe`` created in step 5.
421+
422+
7. Create a directory to host UV projects under ``C:\shared\uv\``
423+
424+
::
425+
426+
cd C:\shared\uv\
427+
mkdir uv_projects
428+
cd uv_projects
429+
430+
8. Create a new *uv* project and install ActivitySim using either :ref:`Option 1: From PyPI` or :ref:`Option 2: From Source with Lockfile` as described above.
431+
432+
9. Ensure that all users have read and execute permissions to the shared uv directory.
433+
434+
::
435+
436+
icacls C:\shared\uv /reset /T
437+
383438
If I use the From PyPI option to install ActivitySim, would I run into dependency issues?
384439
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
385440
Using the :ref:`Option 1: From PyPI` option to install ActivitySim may result in different versions of deep dependencies than those tested by ActivitySim developers.
386-
This is because the :ref:`Option 1: From PyPI` option installs only the direct dependencies listed in ActivitySim's `pyproject.toml` file,
441+
This is because the :ref:`Option 1: From PyPI` option installs only the direct dependencies listed in ActivitySim's ``pyproject.toml`` file,
387442
and relies on *uv* to resolve and install the deep dependencies. It is likely that a newer version of ActivitySim deep dependencies
388-
may cause compatibility issues. For example, see this recent update with `numexpr`: https://github.com/pydata/numexpr/issues/540
443+
may cause compatibility issues. For example, see this recent update with ``numexpr``: https://github.com/pydata/numexpr/issues/540
389444

390445
When that happens, we recommend using the :ref:`Option 2: From Source with Lockfile` option to install ActivitySim, which ensures that
391446
you are using the exact same deep dependencies as those tested by ActivitySim developers. In the meantime, you can also
392447
report the compatibility issues to the ActivitySim development team via GitHub Issues, so that they can address them in future releases.
393448

394-
If I want to use `uv run` to run ActivitySim commands, do I still need to activate the virtual environment?
449+
If I want to use ``uv run`` to run ActivitySim commands, do I still need to activate the virtual environment?
395450
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
396-
No, if you use `uv run` to run ActivitySim commands, you do not need to activate the virtual environment first.
397-
However, you will need to call `uv run` in the project directory where the virtual environment is located. Also, like `uv sync`,
398-
`uv run` automatically updates the lockfile and installs any missing dependencies before running the command.
451+
No, if you use ``uv run`` to run ActivitySim commands, you do not need to activate the virtual environment first.
452+
However, you will need to call ``uv run`` in the project directory where the virtual environment is located. Also, like ``uv sync``,
453+
``uv run`` automatically updates the lockfile and installs any missing dependencies before running the command.

0 commit comments

Comments
 (0)